Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class node{
- public:
- int data;
- node *next;
- node(int d){
- data = d;
- next=NULL;
- }
- };
- class queue{
- public:
- node*front;
- node*rear;
- queue(){
- front=NULL;
- rear=NULL;
- }
- void enqueue(int x);
- void dequeue();
- void print();
- };
- void queue :: enqueue(int x){
- node* p = new node(x);
- //p->data=x;
- if(rear==NULL){
- rear=p;
- front=rear;
- rear->next=NULL;
- front->next=NULL;
- }else{
- rear->next=rear;
- rear=p;
- }
- }
- void queue :: dequeue(){
- if(front == NULL){
- cout<<"List is empty"<<endl;
- }else{
- front=front->next;
- }
- }
- void queue :: print (){
- if(front==NULL){
- cout<<"List is empty"<<endl;
- }else{
- node *p=front->next;
- while(p != NULL){
- cout<<p->data;
- p=p->next;
- }
- cout<<rear->data;
- }
- }
- int main()
- {
- queue q;
- q.enqueue(1);
- q.enqueue(2);
- q.enqueue(3);
- q.enqueue(4);
- q.enqueue(5);
- q.enqueue(6);
- q.enqueue(7);
- q.enqueue(8);
- q.print();
- /*cout<<"After delete"<<endl;
- q.dequeue();
- q.print();*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement