//BCA Support
//www.bcasupport.xyz
#include <iostream.h>
#include <conio.h>
struct queue
{
int data;
struct queue *next;
}*front,*rear,*temp;
int ch;
int enqueue();
int dequeue();
int travel();
int display();
int main()
{
while(1)
{
clrscr();
cout<<"\nQueue-\n1. Enqueue\n2. Dequeue\n3. Traversal"
"\n4. Display\n5. Exit\nEnter choice : ";
cin>>ch;
switch(ch)
{
case 1: enqueue(); break;
case 2: dequeue(); break;
case 3: travel(); break;
case 4: display(); break;
default: return 0;
}
}
}
int enqueue()
{
clrscr();
if(front==NULL)
{
front=(struct queue *)new queue;
rear=front;
cout<<"\nEnter data : ";
cin>>rear->data;
rear->next=NULL;
}
else
{
rear->next=(struct queue *)new queue;
rear=rear->next;
cout<<"\nEnter data : ";
cin>>rear->data;
rear->next=NULL;
}
cout<<"\nData enqueued";
getch();
return 0;
}
int dequeue()
{
clrscr();
if(front==NULL)
{
cout<<"\nQueue empty";
getch();
return 0;
}
temp=front;
front=front->next;
delete temp;
cout<<"\nData dequeued";
getch();
return 0;
}
int travel()
{
clrscr();
if(front==NULL)
{
cout<<"\nQueue empty";
getch();
return 0;
}
cout<<"\nData : "<<front->data;
getch();
return 0;
}
int display()
{
clrscr();
if(front==NULL)
{
cout<<"\nQueue empty";
getch();
return 0;
}
temp=front;
while(temp!=NULL)
{
cout<<endl<<temp->data;
temp=temp->next;
}
getch();
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.