CONTOH PROGRAM QUEUE :
#include<iostream.h>
#include<conio.h>
#include<malloc.h>
struct queue
{
int info;
queue *next;
};
queue *head;
queue *tail;
queue *p;
void buat_queue()
{
head = NULL;
tail = NULL;
cout<<"Queue Telah di buat ! "<<endl;
}
void enqueue(int temp)
{
if(head==NULL && tail == NULL)
{
p=(queue *)malloc(sizeof(queue));
p->info=temp;
p->next=NULL;
head=p;
tail=p;
}
else
{
p=(queue *)malloc(sizeof(queue));
p->info=temp;
p->next=NULL;
tail->next=p;
tail=p;
}
}
void tampilkan()
{
p=head;
while(p!=NULL)
{
cout<<p->info<<endl;
p=p->next;
}
}
void dequeue()
{
if(head == tail)
{
p=head;
head=NULL;
tail=NULL;
free(p);
}
else
{
p=head;
head=head->next;
p->next=NULL;
free(p);
}
}
void main()
{
int menu,temp;
do
{
cout<<"1. Buat Queue "<<endl;
cout<<"2. Enqueue "<<endl;
cout<<"3. Dequeue "<<endl;
cout<<"4. Tampilkan "<<endl;
cout<<"5. Keluar "<<endl;
cout<<"Masukkan Menu : ";
cin>>menu;
switch(menu)
{
case 1 :
buat_queue();
break;
case 2 :
cout<<"Masukkan Nilai : ";
cin>>temp;
enqueue(temp);
break;
case 3 :
dequeue();
break;
case 4 :
tampilkan();
break;
case 5 :
break;
default :
cout<<"Pilihan Tidak Ada ! "<<endl;
break;
}
getch();
clrscr();
}while(menu!=5);
}