-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue_using_ll.cpp
More file actions
50 lines (46 loc) · 869 Bytes
/
Copy pathqueue_using_ll.cpp
File metadata and controls
50 lines (46 loc) · 869 Bytes
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
/* Structure of a node in Queue
struct QueueNode
{
int data;
QueueNode *next;
QueueNode(int a)
{
data = a;
next = NULL;
}
};
And structure of MyQueue
struct MyQueue {
QueueNode *front;
QueueNode *rear;
void push(int);
int pop();
MyQueue() {front = rear = NULL;}
}; */
//Function to push an element into the queue.
void MyQueue:: push(int x)
{
if(front ==NULL || rear==NULL)
{
QueueNode* temp = new QueueNode(x);
rear = temp;
front = temp;
}
else{
QueueNode* temp = new QueueNode(x);
rear->next = temp;
rear = temp;
}
}
//Function to pop front element from the queue.
int MyQueue :: pop()
{
if(front == NULL)
{
rear = NULL;
return -1;
}
int ans = front->data;
front = front->next;
return ans;
}