0% found this document useful (0 votes)
19 views8 pages

Stacks

A stack is a linear data structure that follows the LIFO (Last In First Out) principle, where elements added last are removed first. Elements are added to the top of the stack and removed from the top. Stacks are commonly used for nesting, evaluating expressions, function calls, backtracking, and undo sequences. A queue is a linear data structure that follows the FIFO (First In First Out) principle, where elements added first are removed first. Elements are added to the rear of the queue and removed from the front. Queues are commonly used for waiting lists, accessing shared resources, and processing elements in the order they are received.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views8 pages

Stacks

A stack is a linear data structure that follows the LIFO (Last In First Out) principle, where elements added last are removed first. Elements are added to the top of the stack and removed from the top. Stacks are commonly used for nesting, evaluating expressions, function calls, backtracking, and undo sequences. A queue is a linear data structure that follows the FIFO (First In First Out) principle, where elements added first are removed first. Elements are added to the rear of the queue and removed from the front. Queues are commonly used for waiting lists, accessing shared resources, and processing elements in the order they are received.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

STACKS:

• A stack is a linear data structure that can


be accessed only at one of its ends for
storing and retrieving data
• A stack is a Last In, First Out (LIFO) data
structure
• Anything added to the stack goes on the
“top” of the stack
• Anything removed from the stack is taken
from the “top” of the stack
• Things are removed in the reverse order
from that in which they were inserted

• Stacks are used for:


– Any sort of nesting (such as
parentheses)
– Evaluating arithmetic expressions
(and other sorts of expression)
– Implementing function or
method calls
– Keeping track of previous choices
(as in backtracking)
– Keeping track of choices yet to be
made (as in creating a maze)
– Undo sequence in a text editor.
– Auxiliary data structure for
algorithms
– Component of other data
structures
Queue
• A queue is a waiting line that grows by adding elements to its end and
shrinks by taking elements from its front.
• A queue is an FIFO structure: first in/first out.
• In  queuing theory, various scenarios are analyzed and models are built that
use queues for  processing  requests or other  information  in a
predetermined sequence (order).
• A priority queue  can be assigned to enable a particular process, or event, to
be executed out of sequence without affecting overall system operation.
• In priority queues, elements are dequeued according to their priority and
their current
queue position.
• A queue is a waiting line that grows by
adding elements to its end and shrinks by
taking elements from its front
• A queue is a structure in which both ends
are used:
– One for adding new elements
– One for removing them
• A queue is an FIFO structure: First In/First
Out

• The following operations are needed to


properly manage a queue:
– clear() — Clear the queue
– isEmpty() — Check to see if the
queue is empty
– enqueue(el) — Put the element
el at the end of the queue
– dequeue() — Take the first
element from the queue
– front() — Return the first
element in the queue without
removing it

Queue is used when things don’t have to be


processed immediatly, but have to be processed in
First In First Out order. This property of Queue
makes it also useful in the following applications:

• Direct applications
– Waiting lists
– Access to shared resources (e.g.,
printer)
– Multiprogramming
• Indirect applications
– Auxiliary data structure for
algorithms
– Component of other data
structures

You might also like