0% found this document useful (0 votes)
1 views

Queue

its queue

Uploaded by

bismausaf21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Queue

its queue

Uploaded by

bismausaf21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1: #include<iostream>

2: using namespace std;


3: void Enqueue(int queue[], int &f, int &r, i
4: {
5: if(r==n)
6: cout<<"Queue overflow"<<endl;
7: else
8: {
9: r++;
10: queue[r]=x;
11: if(f==-1) f=0;
12: }
13: }
14: int Dequeue(int queue[], int &f, int &r)
15: {
16: if(f==-1)
17: {
18: cout<<"Queue is empty"<<endl;
19: return(-1);
20: }
21: else
22: {
23: int item=queue[f];
24: if(f==r)
25: f=r=-1;
26: else
27: f++;
28: return(item);
29: }
30: }
31: int main()
32: {
33: int Queue[40],size,i,num;
34: cout<<"Enter size of Queue: ";
35: cin>>size;
36: int f,r;
37: f=r=-1;
38: for(i=1;i<=size;i++)
39: {
40: cout<<"Enter value to add: ";
41: cin>>num;
42: Enqueue(Queue,f,r,num,size-1);
43: }
44: cout<<"Data Items of Queue are:\n";
45: for(i=1;i<=size;i++)
46: {
47: int r=Dequeue(Queue,f,r);
48: if(r!=-1) cout<<r<<endl;
49: }
50: return 0;
51: }
52:

You might also like