-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquesta.cpp
More file actions
152 lines (141 loc) · 1.93 KB
/
questa.cpp
File metadata and controls
152 lines (141 loc) · 1.93 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include<iostream>
#include<conio.h>
using namespace std;
struct node
{
int data;
node *next;
};
class stack
{
public:
node *top;
stack()
{
top=NULL;
}
int isempty();
void push(int);
int pop();
}t1,t2;
int stack::isempty()
{
if(top=='\0')
return 1;
else
return 0;
}
void stack::push(int val)
{
node *temp=new node;
temp->next=NULL;
temp->data=val;
if(top=='\0')
top=temp;
else
{
temp->next=top;
top=temp;
}
}
int stack::pop()
{
if(!isempty())
{
node *t=top;
int r=t->data;
if(top->next=='\0')
top='\0';
else
top=top->next;
delete t;
return r;
}
}
class queue
{
public:
void enque();
void deque();
void display();
};
void queue::enque()
{
int x;
{
while(t1.top!='\0')
{
x=t1.pop();
t2.push(x);
}
}
}
void queue::deque()
{
int y;
if(t2.top!='\0')
{
y=t2.pop();
cout<<y<<" deleted successfully...";
getch();
}
}
void queue::display()
{
if(!t2.isempty())
{
node *t=(t2.top);
while(t!='\0')
{
cout<<t->data<<'\t';
t=t->next;
}
}
else
cout<<"\nQueue is empty...";
getch();
}
int main()
{
queue obj;
int a,z,x;
do
{
system("cls");
cout<<"\nThe menu is:"
<<"\n1.Insert elements in queue"
<<"\n2.Delete elements from queue"
<<"\n3.Display the queue"
<<"\n4.Exit";
cout<<"\nEnter your choice:";
cin>>a;
switch(a)
{
case 1:cout<<"\nEnter the element to be inserted:";
cin>>z;
while(z!=-1)
{
if(t2.top!='\0')
{
while(t2.top!='\0')
{
x=t2.pop();
t1.push(x);
}
}
t1.push(z);
cout<<"\nEnter the element to be inserted:";
cin>>z;
}
obj.enque();
break;
case 2:obj.deque();
break;
case 3:obj.display();
break;
case 4:exit(0);
}
}while(a!=4);
getch();
return 0;
}