-
Notifications
You must be signed in to change notification settings - Fork 7
/
47_Queue_LinkedList.cpp
66 lines (62 loc) · 1.29 KB
/
47_Queue_LinkedList.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
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node *next=NULL;
Node(int data){
this->data = data;
this->next = NULL;
}
};
class Queue{
Node *front;
Node *rear;
public:
Queue(int data){
Node *newnode = new Node(data);
front = newnode;
rear = newnode;
}
Queue(){
front = NULL;
rear = NULL;
}
void enQueue(int data){
Node *newnode = new Node(data);
rear->next = newnode;
rear = newnode;
}
void deQueue(){
Node *temp =front;
front = front->next;
delete temp;
}
void Display(){
if(front==NULL){
cout<<"Queue is Empty"<<endl;
return;
}
Node* temp = front;
while(temp!=rear){
cout<<temp->data<<"->";
temp = temp->next;
}
cout<<rear->data<<endl;
return;
}
};
int main()
{
Queue q1(10);
q1.Display();
q1.enQueue(15);
q1.enQueue(20);
q1.enQueue(30);
q1.Display();
q1.deQueue();
q1.Display();
q1.deQueue();
q1.Display();
return 0;
}