-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueueLL.cpp
48 lines (38 loc) · 1.2 KB
/
queueLL.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
#include<bits/stdc++.h>
using namespace std;
class Queue;
class Node{ // node class
int value; // node value
Node* next; // pointer to next node
public:
Node(int v){value = v; next = NULL;} // constructor
friend class Queue; // friend class
};
class Queue{ // queue class
Node *head, *tail; // pointers to head and tail
public:
Queue(){
head = tail = NULL;
} // constructor
~Queue(){}; // destructor
void append(int val){ // definition of function append which appends at tail
Node* n = new Node(val);
if(head == NULL && tail == NULL){
head = tail = n;
}
else{
tail->next = n;
tail = n;
}
}
int get(){ // definition of function get, which returns value at head
return head->value;
}
};
int main(){
Queue q;
q.append(1);
q.append(2);
cout<<q.get()<<endl;
return 0;
}