Debre Markos University: Department of Information Technology
Debre Markos University: Department of Information Technology
Debre Markos University: Department of Information Technology
Page - 1
Source code for array implementation of Queue operations (ENQUEUE and DEQUEUE)
#include<iostream.h> {
#define size 10 int a[size];
int queue[size]; int s;
int front = -1, rear = -1; cout<<"How many elements do you have for
int isempty() queue?(<10):";
{ cin>>s;
return front = = -1; cout<<"\n Enter...\n";
} for(int i=0;i<s; i++)
int isfull() {
{return ((rear = = size-1)); cout<<"\t element "<<(i+1)<<" :";
} cin>>a[i];
void enqueue(int item) enqueue(a[i]);
{ }
if(isfull()) cout<<"\n The queue looks like:\n";
cout<<"Overflow, Queue is full.\n"; display();
else cout<<endl;
{ int t;
queue[++rear]=item; for(int k = 1;k <= s; k++)
if(front = = -1) {
front++; t=dequeue();
} if(k = = 1)
} cout<<"1st deleted item is: "<<t<<endl;
void display() else if(k = = 2)
{int r, f; cout<<"2nd deleted item is: "<<t<<endl;
r =rear; else if(k = = 3)
f=front; cout<<"3rd deleted item is: "<<t<<endl;
while(f != r+1) else
{cout<<queue[f]<<" "; cout<<k<<"th deleted item is: "<<t<<endl;
f=f+1; }
} }
cout<<endl;
}
int dequeue()
{
if(isempty())
{
cout<<"Underflow, Queue is empty.\n";
return NULL;
}
else
return queue[front++];
}
int main()
Page - 2