From abc0d365dea654aecc5fbddd5d2b1833ab989722 Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Wed, 21 Aug 2019 09:17:20 +0800 Subject: [PATCH] Update Queue Using Linked List.cpp --- Data Structure/Queue Using Linked List.cpp | 129 ++++++++++----------- 1 file changed, 63 insertions(+), 66 deletions(-) diff --git a/Data Structure/Queue Using Linked List.cpp b/Data Structure/Queue Using Linked List.cpp index 763534f83..39d7a9ae3 100644 --- a/Data Structure/Queue Using Linked List.cpp +++ b/Data Structure/Queue Using Linked List.cpp @@ -1,92 +1,89 @@ -#include +#include using namespace std; struct node { - int val; - node *next; + int val; + node *next; }; - node *front, *rear; - void Enque(int x) { - if (rear==NULL) - { - node *n= new node; - n->val=x; - n->next=NULL; - rear=n; - front=n; - } + if (rear == NULL) + { + node *n = new node; + n->val = x; + n->next = NULL; + rear = n; + front = n; + } - else - { + else + { - node *n = new node; - n->val=x; - n->next=NULL; - rear->next=n; - rear=n; - } + node *n = new node; + n->val = x; + n->next = NULL; + rear->next = n; + rear = n; + } } void Deque() { - if (rear == NULL && front == NULL) - { - cout<<"\nUnderflow"; - } - else - { - node *t = front; - cout<<"\n"<val<<" deleted"; - front=front->next; - delete t; - if(front == NULL) - rear = NULL; - } + if (rear == NULL && front == NULL) + { + cout << "\nUnderflow"; + } + else + { + node *t = front; + cout << "\n" + << t->val << " deleted"; + front = front->next; + delete t; + if (front == NULL) + rear = NULL; + } } void show() { - node *t=front; - while(t!=NULL) - { - cout<val<<"\t"; - t=t->next; - } + node *t = front; + while (t != NULL) + { + cout << t->val << "\t"; + t = t->next; + } } int main() { - int ch, x; - do - { - cout<<"\n1. Enque"; - cout<<"\n2. Deque"; - cout<<"\n3. Print"; - cout<<"\nEnter Your Choice : "; - cin>>ch; - if (ch==1) - { - cout<<"\nInsert : "; - cin>>x; - Enque(x); - } - else if (ch==2) - { - Deque(); - } - else if (ch==3) - { - show(); - } - } - while(ch!=0); + int ch, x; + do + { + cout << "\n1. Enque"; + cout << "\n2. Deque"; + cout << "\n3. Print"; + cout << "\nEnter Your Choice : "; + cin >> ch; + if (ch == 1) + { + cout << "\nInsert : "; + cin >> x; + Enque(x); + } + else if (ch == 2) + { + Deque(); + } + else if (ch == 3) + { + show(); + } + } while (ch != 0); - return 0; + return 0; } -