×

# Data Structure Tutorial : Queue

 2 Overview: Queue is a data structure where elements is inserted at the front of the list and any element is deleted from the rear of list. So it is called FIFO(First in First out) data structure. Insert operation on a queue is often called enque and delete operation is often called deque. If we insert an element to queue the rear is increment. Similarly If we delete an element from queue the front is increment. The following picture front is an indicator that indicates the front element of the queue and rear is also an indicator that indicates the last element of the queue. Real life applications of stack: Queues abound in everyday life. In our daily life, when we stand on line to get into bus , we make queue. The man who stands first will get into bus first and the man who stand last will get into the bus last. Operation : The following operation are performed in the stack. 1.Enque : To add an element to queue. 2.Deque : To remove an element from the queue. 3.Peek : To get the topmost element in queue. Implementation : Queue can be implemented two ways. using array and using linked list.Here we discuss queue implementation using array . It uses front variable to print the top most element and rear variable to print the bottom most element in the linear array. Initially front=rear=0 In Enqueue operation rear is increased by one and pushed item to queue[rear] In Deque operation front is increased by one. i.e queue[front++] In Peek operation check that the front is not equal to rear and return queue[front]  Algorithm : Enqueue(que, n, item) Step 1: Start Step 2: if(rear==n) print overflow else que[rear++]=item. Step 3: End  `C++ implementation : void Enque(int que[],int n, int item) { if(rear==n) cout<<"Overflow"<

 0 At the top you have that stack is a data structure .... change it to queue answered 22 Nov '16, 09:05 2.6k●3●20 accept rate: 8% 2 I changed it. (22 Nov '16, 09:20) rashedcs1★
 0 Your queue is using O(#of enqueues) space. Typically you wouldn't want this, but rather O(maximal number of items in queue at the same time). answered 22 Nov '16, 03:30 7★ceilks 1.8k●8 accept rate: 36%
 0 Real life applications of stack is mentioned change it to queue ... answered 23 Nov '16, 01:10 3★smsubham 673●2●14 accept rate: 15% Yeap. I edited this. (23 Nov '16, 19:15) rashedcs1★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×773

question asked: 22 Nov '16, 01:33

question was seen: 756 times

last updated: 23 Nov '16, 19:15