-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueRepLL.cxx
More file actions
64 lines (62 loc) · 1.27 KB
/
QueueRepLL.cxx
File metadata and controls
64 lines (62 loc) · 1.27 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
#include<iostream>
using namespace std;
struct node{
int data;
struct node *next;
};
struct node *front=NULL;
struct node *rear=NULL;
struct node *temp;
struct node *newNode;
void enqueue(){
int ele;
cout<<"Enter ele to insert into queue..";
cin>>ele;
newNode = (struct node *)malloc(sizeof(struct node));
newNode->data = ele;
newNode->next = NULL;
if(front==NULL && rear==NULL)
front=rear=newNode;
else{
rear->next = newNode;
rear = newNode;
}
cout<<"\nElement insereted "<<ele;
}
void dequeue(){
temp = front;
if(front==NULL)
cout<<"Queue is Empty.";
else{
cout<<"Deleted item is "<<temp->data;
front = front->next;
free(temp);
}
}
void display(){
newNode = front;
if(front == NULL)
cout<<"Queue is Empty. ";
else{
while(newNode != NULL){
cout<<"\t"<<newNode->data;
newNode = newNode->next;
}
}
}
int main(){
int ch;
do{
cout<<"\n1.Enqueue\n2.Dequeue\n3.Display\n4.Exit\n";
cin>>ch;
if(ch==1)
enqueue();
else if(ch==2)
dequeue();
else if(ch==3)
display();
else
exit(0);
}while(ch<4);
return 1;
}