-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.h
56 lines (48 loc) · 1.2 KB
/
queue.h
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;
// Structure to create a node with data and the next pointer
struct node {
public:
string data;
node * next;
};
class Queue {
public:
node *front = nullptr;
node *rear = nullptr;
// Enqueue() operation on a queue
void enqueue(string value) {
node *ptr = new node();
ptr -> data = value;
ptr -> next = NULL;
if ((front == NULL) && (rear == NULL)) {
front = ptr;
rear = ptr;
} else {
rear -> next = ptr;
rear = ptr;
}
cout << value << " Added to Downloads!" << endl;
}
// Dequeue() operation on a queue
string dequeue() {
if (front == NULL) {
cout << "Queue underflow error!";
return "";
} else {
node * temp = front;
string temp_data = front -> data;
front = front -> next;
free(temp);
return temp_data;
}
}
void display() {
cout << "Downloading Apps Queue: ";
while(front!=NULL) {
cout << front->data << ", ";
front = front->next;
}
cout << endl;
}
};