-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCQUEUE.CPP
More file actions
104 lines (97 loc) · 1.62 KB
/
Copy pathCQUEUE.CPP
File metadata and controls
104 lines (97 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include<iostream.h>
#include<conio.h>
#include<process.h>
int c_q[40],res,front=-1,rear=-1;
void disp()
{
cout<<"Note :Free space is '-',rear '<<<',front '>>>'"<<endl;
int i=0;
if(front==-1)
return ;
if(rear >=front)
{
for(i=0;i<front;i++)
cout<<"-";
cout<<">>>"<<endl;
for(i=front;i<rear;i++)
cout<<c_q[i]<<"<-";
cout<<c_q[rear]<<"<<<"<<endl;
}
else
{
for(i=0;i<rear;i++)
cout<<c_q[i]<<"<-";
cout<<c_q[rear]<<"<<<";
for(;i<front;i++)
cout<<"-";
cout<<">>>";
for(i=front;i<40;i++)
cout<<c_q[i]<<"<-";
cout<<"\t";
}
}
void push()
{
int item;
cout<<"Enter item"<<endl;
cin>>item;
if((front==0 && rear==39) || (front==rear+1))
{
cout<<"Overflow"<<endl;
return ;
}
else if(rear==-1)
front=rear=0;
else if(rear==39)
rear=0;
else
rear++;
c_q[rear]=item;
cout<<endl<<"Now queue is"<<endl;
disp();
}
void pop()
{
int ret;
ret=c_q[front];
if(front==-1)
{
cout<<"Can't be done"<<endl;
return ;
}
if(front==rear)
front=rear=-1;
else if(front==39)
front=0;
else
front++;
cout<<"Element deleted is"<<endl<<ret<<endl<<endl;
cout<<"Now the queue is"<<endl;
disp();
}
void main()
{
int choice;
char ans;
do
{
clrscr();
cout<<"1.Push"<<endl;
cout<<"2.Pop"<<endl;
cout<<"3.Display"<<endl;
cout<<"4.Exit"<<endl;
cin>>choice;
if(choice==4)
exit(0);
else if(choice==1)
push();
else if(choice==2)
pop();
else if(choice==3)
disp();
else
cout<<"enter valid choice"<<endl;
cout<<endl<<"continue?"<<endl;
cin>>ans;
}while(ans=='y');
}