-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12]fds_program_for_queue_dequeue.cpp
123 lines (122 loc) · 2.6 KB
/
12]fds_program_for_queue_dequeue.cpp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include<iostream>
using namespace std;
#define SIZE 10
class DeQueue {
int Arr[20],Front,Rear;
public:
DeQueue();
void AddAtBegin(int);
void AddAtEnd(int);
void DelFront();
void DelRear();
void Display();
};
DeQueue::DeQueue() {
Front=-1;
Rear=-1;
}
void DeQueue::AddAtEnd(int i) {
if(Rear>=SIZE-1) {
cout<<"\n OverFlow occured";
} else {
if(Front==-1) {
Front++;
Rear++;
} else {
Rear=Rear+1;
}
Arr[Rear]=i;
cout<<"\nInserted Element Is: "<<Arr[Rear];
}
}
void DeQueue::AddAtBegin(int i) {
if(Front==-1) {
Front=0;
Arr[++Rear]=i;
cout<<"\n Inserted Element Is: "<<i;
} else if(Front!=0) {
Arr[--Front]=i;
cout<<"\n Inserted Element Is: "<<i;
} else {
cout<<"\n OverFlow occured";
}
}
void DeQueue::DelFront() {
if(Front==-1) {
cout<<"Dequeue Is Empty";
return;
}
else {
cout<<"Deleted Element: "<<Arr[Front];
if(Front==Rear) {
Front=Rear=-1;
return;
} else
Front=Front+1;
}
}
void DeQueue::DelRear() {
if(Front==-1) {
cout<<"Dequeue Is Empty";
return;
}
else {
cout<<"Deleted Element: "<<Arr[Rear];
if(Front==Rear) {
Front=Rear=-1;
} else
Rear=Rear-1;
}
}
void DeQueue::Display() {
if(Front==-1) {
cout<<"Dequeue is empty";
} else {
for(int i=Front;i<=Rear;i++) {
cout<<Arr[i]<<" ";
}
}
}
int main() {
int ch,i;
DeQueue De1;
do
{
cout<<"\n 1.Add At Beginning";
cout<<"\n 2.Add At End";
cout<<"\n 3.Display";
cout<<"\n 4.Delete From Front";
cout<<"\n 5.Delete From Rare";
cout<<"\n 6.Exit";
cout<<"\n Enter Your Choice: ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter The Element To Be Added: ";
cin>>i;
De1.AddAtBegin(i);
break;
case 2:
cout<<"Enter The Element To Be Added: ";
cin>>i;
De1.AddAtEnd(i);
break;
case 3:
De1.Display();
break;
case 4:
De1.DelFront();
break;
case 5:
De1.DelRear();
break;
case 6:
exit(1);
break;
default:
cout<<"Invalid Choice";
break;
}
}while(ch!=7);
}