#include
#define maks 5
using namespace std;
class node{
public:
char data;
node *next;
};
class queue{
friend ostream& operator<<(ostream&, const queue&);
public:
queue();
int penuh(int);
int kosong(int);
void cetak();
void enqueue(char);
char dequeue();
private:
char a[maks];
int banyak;
node *first;
node *last;
};
ostream& operator<<(ostream& out,const queue& s){
if(s.banyak==0){cout<<"\nQueue Kosong!!";
}else{
cout<<"\nIsi Queue sebanyak "<
for(int i=0;i
out<
}
}
queue::queue(){
first=NULL;
last=NULL;
banyak=0;
for(int i=0;i
a[i]='0';
}
int queue::penuh(int s){
return s==maks?1:0;
}
int queue::kosong(int s){
return s==0?1:0;
}
void queue::cetak(){
cout<<"\nIsi Queue: ";
for(int i=0;i>banyak;i++)
cout<<<" ";
}
void queue::enqueue(char data){
if(first == NULL){
first = new node();
first->data = data;
last = first;
}else{
last->next = new node();
last->next->data = data;
last = last->next;
}
cout<<"\nElemen: "<<<" masuk antrian";
if(penuh(banyak))cout<<"\nMaaf,elemen "<<<" tidak bisa masuk antrian!!\nQueue penuh";
else if(a[0]=='0'){
a[0]=data;
banyak++;
}else{
int tempat=0;
while(a[tempat]>data)tempat++;
if(banyak!=tempat)
for(int i=banyak;i>=tempat;i--)
a[i+1]=a[i];
a[tempat]=data;
banyak++;
}
}
char queue::dequeue(){
char reval = NULL;
node *point;
point = first;
if(first!=NULL){
first = first->next;
reval = point->data;
delete point;
}
char temp=a[--banyak];
cout<<"\n\nDequeue elemen --> "<
a[banyak]='0';
return temp;
}
int main(int argc, char *argv[])
{
queue p;
char a,b,c,d;
cout<<"Masukkan data antrian: ";
cin>>a;
p.enqueue(a);
cout<
cout<<"\n\nMasukkan data antrian: ";
cin>>b;
p.enqueue(b);
cout<
cout<<"\n\nMasukkan data antrian: ";
cin>>c;
p.enqueue(c);
cout<
cout<<"\n\nMasukkan data antrian: ";
cin>>d;
p.enqueue(d);
cout<
//cout<<"\n\nMasukkan data antrian: ";
//cin>>e;
//p.enqueue(e);
//cout<
///cout<<"\n\nMasukkan data antrian: ";
//cin>>f;
//p.enqueue(f);
//cout<
char x=p.dequeue(); // char y=p.dequeue(); // char z=p.dequeue(); // char xy=p.dequeue(); // char xyz=p.dequeue(); cout<
cout<<"\nElemen yang di-dequeue "<
cout<
// cout<<"\nElemen yang di-dequeue "<
// cout<
// cout<<"\nElemen yang di-dequeue "<
// cout<
// cout<<"\nElemen yang di-dequeue "<
// cout<
// cout<<"\nElemen yang di-dequeue "<
// cout<
system("PAUSE");
return EXIT_SUCCESS;
}
Tidak ada komentar:
Posting Komentar