Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class node{
- public:
- int value;
- node *next;
- node(int value){
- this->value = value;
- this->next = NULL;
- }
- };
- class queue{
- public:
- node *head;
- node *tail;
- int count;
- queue(){
- this->head = NULL;
- this->tail = NULL;
- this->count = 0;
- }
- bool is_empty(){
- return !this->count;
- }
- int push(node *n){
- if(this->tail == NULL)
- this->head = n;
- else
- this->tail->next = n;
- this->tail = n;
- this->count +=1;
- return 0;
- }
- node * pop(){
- node *n = this->head;
- this->head = n->next;
- this->count -=1;
- if(this->head == NULL)
- this->tail = NULL;
- return n;
- }
- };
- int main(int argc, char const *argv[])
- {
- queue *q = new queue();
- node *n1 = new node(3);
- q->push(n1);
- node *n2 = q->pop();
- cout<<n2->value;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement