forked from dhruvchadha2212/codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcirqueuell.cpp
More file actions
71 lines (70 loc) · 1.1 KB
/
cirqueuell.cpp
File metadata and controls
71 lines (70 loc) · 1.1 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
#include<bits/stdc++.h>
using namespace std;
struct node {
int data;
struct node* next;
};
struct node *front = NULL, *rear = NULL;
void qinsert(int val) {
struct node* temp = (struct node*)malloc(sizeof(node));
temp->data = val;
if(rear == NULL) {
front = rear = temp;
rear->next = temp;
}
else {
rear->next = temp;
temp->next = front;
rear = temp;
}
cout<<"Inserted\n";
}
void qdelete() {
if(rear == NULL) {
cout<<"Queue empty\n";
}
else if(rear == front) {
front = rear = NULL;
cout<<"Deleted\n";
}
else {
rear->next = front->next;
free(front);
front = rear->next;
cout<<"Deleted\n";
}
}
void traverse() {
if(rear == NULL) {
cout<<"Queue empty\n";
}
else {
struct node* temp = front;
while(temp != rear) {
cout<<temp->data<<" ";
temp = temp->next;
}
cout<<temp->data<<endl;
}
}
int main() {
int choice;
while(1) {
cout<<"1) Enter\n2) Delete\n3) Traverse\n";
cin>>choice;
switch(choice) {
case 1:
cout<<"Enter value\n";
int t;
cin>>t;
qinsert(t);
break;
case 2:
qdelete();
break;
case 3:
traverse();
break;
}
}
}