-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpro24.cpp
84 lines (78 loc) · 1.18 KB
/
pro24.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
#include <iostream>
#include <cstddef>
using namespace std;
struct node{
int info;
node *link;
};
struct node *front = NULL;
struct node *rear = NULL;
int count = 0;
void ins(){
node *n;
int data;
n = new node;
cout<<"enter data:\n";
cin>>data;
n->info = data;
if(count==0){
front = n;
rear = n;
} else {
rear->link = n;
rear = n;
}
count+=1;
}
void del(){
node *temp;
temp = front;
if(count==0){
cout<<"queue is empty!\n";
} else if(front==rear){
front = NULL;
rear = NULL;
cout<<"entry deleted\n";
delete temp;
count-=1;
}else{
front = front->link;
cout<<"entry deleted\n";
delete temp;
count-=1;
}
}
void display(){
if(count!=0){
int i = 0;
node *next;
int data = front->info;
cout<<data<<"\t";
next = front->link;
while(i<count-1){
data = next->info;
cout<<data<<"\t";
next = next->link;
i++;
}} else
cout<<"no data in queue!";
}
int main(){
int c = 0;
while(c!=4){
cout<<"\nEnter choice:\n1.insert\n2.delete\n3.display\n4.exit";
cin>>c;
switch(c){
case 1: ins();
break;
case 2: del();
break;
case 3: display();
break;
case 4: "exit";
break;
default: cout<<"incorrect choice";
}
}
return 0;
}