-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwentyThird.cpp
55 lines (55 loc) · 1001 Bytes
/
twentyThird.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
#include <iostream>
using namespace std;
struct node {
int data;
node* next;
};
node* rear;
node* front;
node* getNewNode(int x)
{
node* temp = new node();
temp->next = NULL;
temp->data = x;
return temp;
}
void enqueue(int x) {
node* temp = getNewNode(x);
if(rear == NULL && front == NULL){
rear = front = temp;
}
else{
rear -> next = temp;
rear = temp;
}
}
void dequeue(/* arguments */) {
node* temp = front;
front = front->next;
delete temp;
}
void display(/* arguments */) {
node* temp = front;
while (temp != NULL) {
std::cout << temp->data << '\n';
temp = temp->next;
}
}
int main(int argc, char const *argv[]) {
rear = front = NULL;
enqueue(10);
enqueue(20);
enqueue(30);
enqueue(40);
enqueue(50);
enqueue(60);
enqueue(70);
enqueue(80);
display();
std::cout << '\n';
dequeue();
dequeue();
dequeue();
display();
return 0;
}