1.
QUEUE USING ARRAY
#include<iostream.h> #include<conio.h> #include<stdlib.h> #define max 5 class queue { private: int top,item[max],front,rear; public: queue() { rear=front=-1; } void add(); void del(); void display(); }; void queue::add() { int x; if(rear==max-1) cout<<"\n Queue is full"; else { rear++; cout<<"\n Enter the element:"; cin>>x; item[rear]=x; }
} void queue::del() { int x; if(front==rear) cout<<"\n Queue is empty"; else { front++; x=item[front]; cout<<"\n Popped element is:"<<x; } } void queue::display() { if(front==rear) cout<<"\n Queue is empty"; else { for(int i=front+1;i<rear;i++) { cout<<"\n Element is:"<<i+1<<item[i]; } } } void main() { queue q; int ch; clrscr(); cout<<"\n\t\t Queue using arrays"; cout<<"\[Link]\[Link]\[Link]\[Link]"; do
{ cout<<"\n Enter your choice:"; cin>>ch; switch(ch) { case 1: [Link](); break; case 2: [Link](); break; case 3: [Link](); break; } } while(ch!=4); getch(); }
OUTPUT:
Queue using arrays
[Link] [Link] [Link] [Link] Enter your choice:1 Enter the element:56 Enter your choice:1 Enter the element:45 Enter your choice:2 Popped element is:56 Enter your choice:3 Element is:45 Enter your choice:4