SlideShare a Scribd company logo
1 of 9
Difference Between Stack and Queue
By- Pulkit Modi
St
ack and Queue both are the non-primitive data structures. The main
differences between stack and queue are that stack uses LIFO (last in first
out) method to access and add data elements whereas Queue uses FIFO
(First in first out) method to access and add data elements.
St
ack has only one end open for pushing and popping the data elements on
the other hand Queue has both ends open for enqueuing and dequeuing the
data elements.
St
ack and queue are the data structures used for storing data elements and
are actually based on some real world equivalent. For example, the stack is
a stack of CD’s where you can take out and put in CD through the top of the
stack of CDs. Similarly, The queue is a queue for Theatre tickets where the
person standing in the first place, i.e., front of the queue will be served first
and the new person arriving will appear in the back of the queue (rear end
of the queue).
Content: Stack Vs Queue
1. Comparison
Chart
2. Definition
3. Key
Differences
4. Implementati
on
5. Operations
6. Applications
BASIS FOR
COMPARISON
STACK QUEUE
Working principle LIFO (Last in First
out)
FIFO (First in First out)
Structure Same end is used to
insert and delete
elements.
One end is used for insertion, i.e., rear end and
another end is used for deletion of elements, i.e.,
front end.
Number of pointers
used
One Two (In simple queue case)
Operations performed Push and Pop Enqueue and dequeue
Examination of empty
condition
Top == -1 Front == -1 || Front == Rear + 1
Examination of full
condition
Top == Max - 1 Rear == Max - 1
Variants It does not have
variants.
It has variants like circular queue, priority
queue, doubly ended queue.
Implementation Simpler Comparatively complex
7. Conclusion
Comparison Chart
Definition of Stack
A Stack is a non-primitive linear data structure. It is an ordered list where
the new item is added and existing element is deleted from only one end,
called as the top of the stack (TOS). As all the deletion and insertion in a
stack is done from the top of the stack, the last element added will be the
first to be removed from the stack. That is the reason why stack is called
Last-in-First-out (LIFO) type of list.
Note that the element often accessed in the stack is the topmost element,
whereas the last available element is in the bottom of the stack.
Example
Some of you may eat biscuits (or Poppins). If you assume, only one side of
the cover is torn, and biscuits are taken out one by one. This is what is
called popping, and similarly, if you want to preserve some biscuits for some
time later, you will put them back into the pack through the same torn end
is called pushing.
Definition of Queue
A queue is a linear data structure comes in the category of the non-primitive
type. It is a collection of similar type of elements. The addition of new
elements takes place at one end called rear end. Similarly, deletion of the
existing elements takes place at the other end called the Front-end, and it is
logically a First in first out (FIFO) type of list.
Example
In our day to day life we come across many situations where we out to wait
for the desired service, there we have to get into waiting line for our turn to
get serviced. This waiting queue can be thought of as a queue.
Key Differences Between Stack and Queue
1. Stack follows LIFO mechanism on the other hand Queue follows FIFO
mechanism to add and remove elements.
1. In a stack, the same end is used to insert and delete the
elements. On the contrary, two different ends are used in the queue to
insert and delete the elements.
2. As Stack have only one open end that is the reason for using
only one pointer to refer to the top of the stack. But queue uses two
pointers to refer front and the rear end of the queue.
3. Stack performs two operations known as push and pop while
in Queue its known as enqueue and dequeue.
4. Stack implementation is easier whereas Queue implementation
is tricky.
5. Queue has variants like circular queue, priority queue, doubly
ended queue, etc. In contrast, stack does not have variants.
Stack Implementation
The stack can be applied in two ways :
1. Static implementation uses arrays to create a stack. Static
implementation is though an effortless technique but is not a flexible
way of creation, as the declaration of the size of the stack has to be
done during program design, after that the size cannot be varied.
Additionally, static implementation is not very efficient regarding
memory utilization. Since an array (for implementing stack) is declared
before the start of the operation (at program design time). Now if the
number of elements to be sorted is very less in the stack the statically
allocated memory will be wasted. On the other hand, if there are more
number of elements to be stored in the stack then, we can’t be able to
change the size of the array to increase its capacity, so that it can
accommodate new elements.
2. Dynamic implementation is also called linked list
representation and uses pointers to implement the stack type of data
structure.
Queue Implementation
Queue can be implemented in two ways:
1. Static implementation: If a queue is implemented using arrays, the
exact number of elements we want to store in the queue must be
assured prior, because the size of the array has to be declared at
design time or before the processing starts. In this case, the beginning
of the array will become the front of the queue, and the last location of
the array will act as the rear of the queue. The following relation gives
the whole elements exist in the queue when implemented using arrays:
front – rear + 1
If “rear < front” then there will be no element in the queue or queue will
always be empty.
2. Dynamic implementation: Implementing queues using pointers, the
main disadvantage is that a node in a linked representation consumes
more memory space than a corresponding element in the array
representation. Since there are at least two fields in each node one for
the data field and other to store the address of the next node whereas
in linked representation only data field is there. The merit of using the
linked representation becomes obvious when it is required to insert or
delete an element in the middle of a group of other elements.
Operations on Stack
The basic operations that can be operated on the stack are as follows:
1. PUSH: when a new element is added to the top of the stack is
known as PUSH operation. Pushing an element in the stack invokes
adding of the element, as the new element will be inserted at the top.
After each push operation, the top is increased by one. If the array is
full, and no new element can be added, it is called STACK-FULL
condition or STACK OVERFLOW. PUSH OPERATION – function in C:
Considering stack is declared as
int stack [5], top = -1;
void push()
{
int item; if (top < 4)
{
printf ("Enter the number") ; scan ("%d", & item) ;
top = top + 1;
stack [top] = item;
}
else
{
printf (" Stack is full");
}
}
1. POP: When an element is deleted from the top of the stack it is
known as POP operation. The stack is decreased by one, after every
pop operation. If there is no element left on the stack and the pop is
performed, then this will result in STACK UNDERFLOW condition which
means your stack is Empty. POP OPERATION – functions in C:
Considering stack is declared as
int stack [5], top = -1;
void pop()
{
int item;
if (top >= 4)
{
item = stack [top]; top = top - 1;
printf ("Number deleted is = %d", item) ;
}
else
{
printf (" Stack is empty");
}
}
Operations on a Queue
The basic operations that can be performed on queue are:
1. Enqueue: To insert an element in a queue.Enqueuing operation
function in C:
Queue is declared as
int queue [5], Front = -1 and rear = -1;
void add ()
{
int item; if ( rear < 4)
{
printf ("Enter the number") ; scan ("%d", & item) ; if (front == -1)
{
front =0 ; rear =0 ;
}
else
{
rear = rear + 1;
}
queue [rear] = item ;
}
else
{
printf ("Queue is full") ;
}
}<br>
1. Dequeue: To delete an element from the queue.Enqueuing
operation function in C:
Queue is declared as
int queue [5], Front = -1 and rear = -1;
void delete ()
{
int item;
if ( front ! = -1)
{
item = queue [ front ] ;
if (front == rear)
{
front =-1 ; rear =-1 ;
}
else
{
front = front + 1;
printf ("Number deleted is = %d", item) ;
}
}
else
{
printf ("Queue is empty") ;
}
}
Applications of Stack
 Parsing in a compiler.
 Java virtual machine.
 Undo in a word processor.
 Back button in a Web browser.
 PostScript language for printers.
 Implementing function calls in a compiler.
Applications of Queue
 Data Buffers
 Asynchronous data transfer (file IO, pipes, sockets).
 Allotting requests on a shared resource (printer, processor).
 Traffic analysis.
 Determine the number of cashiers to have at a supermarket.
Conclusion
Stack and Queue are linear data structures differ in certain ways like
working mechanism, structure, implementation, variants but both are used
for storing the elements in the list and performing operations on the list like
addition and deletion of the elements. Although there are some limitations of
the simple queue which is recouped by using other types of queue.
Thank You

More Related Content

What's hot

Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
Jsaddam Hussain
 
Linked list
Linked listLinked list
Linked list
VONI
 

What's hot (20)

Stacks
StacksStacks
Stacks
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
Linked list
Linked listLinked list
Linked list
 
Array data structure
Array data structureArray data structure
Array data structure
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Queue
QueueQueue
Queue
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Quick sort
Quick sortQuick sort
Quick sort
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Linked lists
Linked listsLinked lists
Linked lists
 
Quick sort
Quick sortQuick sort
Quick sort
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 

Similar to Difference between stack and queue

Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
TobyWtf
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 

Similar to Difference between stack and queue (20)

VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
DS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptxDS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptx
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
stack 1.pdf
stack 1.pdfstack 1.pdf
stack 1.pdf
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
 
Queue
QueueQueue
Queue
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Difference between stack and queue

  • 1. Difference Between Stack and Queue By- Pulkit Modi St ack and Queue both are the non-primitive data structures. The main differences between stack and queue are that stack uses LIFO (last in first out) method to access and add data elements whereas Queue uses FIFO (First in first out) method to access and add data elements. St ack has only one end open for pushing and popping the data elements on the other hand Queue has both ends open for enqueuing and dequeuing the data elements. St ack and queue are the data structures used for storing data elements and are actually based on some real world equivalent. For example, the stack is a stack of CD’s where you can take out and put in CD through the top of the stack of CDs. Similarly, The queue is a queue for Theatre tickets where the person standing in the first place, i.e., front of the queue will be served first and the new person arriving will appear in the back of the queue (rear end of the queue). Content: Stack Vs Queue 1. Comparison Chart 2. Definition 3. Key Differences 4. Implementati on 5. Operations 6. Applications
  • 2. BASIS FOR COMPARISON STACK QUEUE Working principle LIFO (Last in First out) FIFO (First in First out) Structure Same end is used to insert and delete elements. One end is used for insertion, i.e., rear end and another end is used for deletion of elements, i.e., front end. Number of pointers used One Two (In simple queue case) Operations performed Push and Pop Enqueue and dequeue Examination of empty condition Top == -1 Front == -1 || Front == Rear + 1 Examination of full condition Top == Max - 1 Rear == Max - 1 Variants It does not have variants. It has variants like circular queue, priority queue, doubly ended queue. Implementation Simpler Comparatively complex 7. Conclusion Comparison Chart
  • 3. Definition of Stack A Stack is a non-primitive linear data structure. It is an ordered list where the new item is added and existing element is deleted from only one end, called as the top of the stack (TOS). As all the deletion and insertion in a stack is done from the top of the stack, the last element added will be the first to be removed from the stack. That is the reason why stack is called Last-in-First-out (LIFO) type of list. Note that the element often accessed in the stack is the topmost element, whereas the last available element is in the bottom of the stack. Example Some of you may eat biscuits (or Poppins). If you assume, only one side of the cover is torn, and biscuits are taken out one by one. This is what is called popping, and similarly, if you want to preserve some biscuits for some time later, you will put them back into the pack through the same torn end is called pushing.
  • 4. Definition of Queue A queue is a linear data structure comes in the category of the non-primitive type. It is a collection of similar type of elements. The addition of new elements takes place at one end called rear end. Similarly, deletion of the existing elements takes place at the other end called the Front-end, and it is logically a First in first out (FIFO) type of list. Example In our day to day life we come across many situations where we out to wait for the desired service, there we have to get into waiting line for our turn to get serviced. This waiting queue can be thought of as a queue. Key Differences Between Stack and Queue 1. Stack follows LIFO mechanism on the other hand Queue follows FIFO mechanism to add and remove elements.
  • 5. 1. In a stack, the same end is used to insert and delete the elements. On the contrary, two different ends are used in the queue to insert and delete the elements. 2. As Stack have only one open end that is the reason for using only one pointer to refer to the top of the stack. But queue uses two pointers to refer front and the rear end of the queue. 3. Stack performs two operations known as push and pop while in Queue its known as enqueue and dequeue. 4. Stack implementation is easier whereas Queue implementation is tricky. 5. Queue has variants like circular queue, priority queue, doubly ended queue, etc. In contrast, stack does not have variants. Stack Implementation The stack can be applied in two ways : 1. Static implementation uses arrays to create a stack. Static implementation is though an effortless technique but is not a flexible way of creation, as the declaration of the size of the stack has to be done during program design, after that the size cannot be varied. Additionally, static implementation is not very efficient regarding memory utilization. Since an array (for implementing stack) is declared before the start of the operation (at program design time). Now if the number of elements to be sorted is very less in the stack the statically allocated memory will be wasted. On the other hand, if there are more number of elements to be stored in the stack then, we can’t be able to change the size of the array to increase its capacity, so that it can accommodate new elements. 2. Dynamic implementation is also called linked list representation and uses pointers to implement the stack type of data structure. Queue Implementation Queue can be implemented in two ways: 1. Static implementation: If a queue is implemented using arrays, the exact number of elements we want to store in the queue must be assured prior, because the size of the array has to be declared at design time or before the processing starts. In this case, the beginning of the array will become the front of the queue, and the last location of the array will act as the rear of the queue. The following relation gives
  • 6. the whole elements exist in the queue when implemented using arrays: front – rear + 1 If “rear < front” then there will be no element in the queue or queue will always be empty. 2. Dynamic implementation: Implementing queues using pointers, the main disadvantage is that a node in a linked representation consumes more memory space than a corresponding element in the array representation. Since there are at least two fields in each node one for the data field and other to store the address of the next node whereas in linked representation only data field is there. The merit of using the linked representation becomes obvious when it is required to insert or delete an element in the middle of a group of other elements. Operations on Stack The basic operations that can be operated on the stack are as follows: 1. PUSH: when a new element is added to the top of the stack is known as PUSH operation. Pushing an element in the stack invokes adding of the element, as the new element will be inserted at the top. After each push operation, the top is increased by one. If the array is full, and no new element can be added, it is called STACK-FULL condition or STACK OVERFLOW. PUSH OPERATION – function in C: Considering stack is declared as int stack [5], top = -1; void push() { int item; if (top < 4) { printf ("Enter the number") ; scan ("%d", & item) ; top = top + 1; stack [top] = item; } else { printf (" Stack is full"); } } 1. POP: When an element is deleted from the top of the stack it is known as POP operation. The stack is decreased by one, after every pop operation. If there is no element left on the stack and the pop is performed, then this will result in STACK UNDERFLOW condition which means your stack is Empty. POP OPERATION – functions in C: Considering stack is declared as int stack [5], top = -1; void pop() { int item;
  • 7. if (top >= 4) { item = stack [top]; top = top - 1; printf ("Number deleted is = %d", item) ; } else { printf (" Stack is empty"); } } Operations on a Queue The basic operations that can be performed on queue are: 1. Enqueue: To insert an element in a queue.Enqueuing operation function in C: Queue is declared as int queue [5], Front = -1 and rear = -1; void add () { int item; if ( rear < 4) { printf ("Enter the number") ; scan ("%d", & item) ; if (front == -1) { front =0 ; rear =0 ; } else { rear = rear + 1; } queue [rear] = item ; } else { printf ("Queue is full") ; } }<br> 1. Dequeue: To delete an element from the queue.Enqueuing operation function in C: Queue is declared as int queue [5], Front = -1 and rear = -1; void delete () { int item; if ( front ! = -1) { item = queue [ front ] ; if (front == rear) { front =-1 ; rear =-1 ;
  • 8. } else { front = front + 1; printf ("Number deleted is = %d", item) ; } } else { printf ("Queue is empty") ; } } Applications of Stack  Parsing in a compiler.  Java virtual machine.  Undo in a word processor.  Back button in a Web browser.  PostScript language for printers.  Implementing function calls in a compiler. Applications of Queue  Data Buffers  Asynchronous data transfer (file IO, pipes, sockets).  Allotting requests on a shared resource (printer, processor).  Traffic analysis.  Determine the number of cashiers to have at a supermarket. Conclusion Stack and Queue are linear data structures differ in certain ways like working mechanism, structure, implementation, variants but both are used for storing the elements in the list and performing operations on the list like addition and deletion of the elements. Although there are some limitations of the simple queue which is recouped by using other types of queue.