diff --git a/Linear_DS/queue.cpp b/Linear_DS/queue.cpp new file mode 100755 index 0000000..ea0bfd0 --- /dev/null +++ b/Linear_DS/queue.cpp @@ -0,0 +1,99 @@ +#include +using namespace std; +class QNode +{ + public: + int key; + QNode *next; + QNode(int data) + { + this->key=data; + this->next=NULL; + } +}; +struct Queue +{ + QNode *front, *rear; + int size=0; + Queue() + { + this->front=NULL; + this->rear=NULL; + } + void enqueue(int val) + { + QNode* node=new QNode(val); + node->next=NULL; + if(front==NULL) + { + front=rear=node; + rear->next=NULL; + } + else + { + rear->next=node; + rear=node; + rear->next=NULL; + } + size++; + cout<<"enqueued sucessfully"<key<<" "; + temp=temp->next; + t++; + } + cout<next; + delete node; + } + front=rear=NULL; + } + QNode *dequeue() + { + if(front==NULL) + return NULL; + else + { + QNode* node=front; + front=front->next; + size--; + cout<<"dequeued sucessfully"<key<<" "; + temp=temp->next; + } + cout<next; + delete node; + } + top=NULL; + } + QNode *pop() + { + if(top==NULL) + return NULL; + else + { + QNode* node=top; + top=top->next; + size--; + //cout<<"poped sucessfully"<