Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views22 pages

Stack

The document explains the concept of stacks and queues, detailing their operations such as 'push' and 'pop' for stacks, and the FIFO nature of queues. It also introduces different notations for arithmetic expressions: infix, prefix, and postfix. Additionally, it covers deques, which allow operations at both ends, and priority queues that process elements based on assigned priorities.

Uploaded by

tachbirdewan.bd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views22 pages

Stack

The document explains the concept of stacks and queues, detailing their operations such as 'push' and 'pop' for stacks, and the FIFO nature of queues. It also introduces different notations for arithmetic expressions: infix, prefix, and postfix. Additionally, it covers deques, which allow operations at both ends, and priority queues that process elements based on assigned priorities.

Uploaded by

tachbirdewan.bd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

STACK

STACK
 A stack is a list of elements in which an element may be
inserted or deleted only at one end, called the top of the
stack.
 This means, in particular, that elements are removed

from a stack in the reverse order of that in which they


were inserted into the stack.
 Special terminology is used for two basic
operations associated with stacks:
(a) “Push” is the term used to insert an
element into a stack.
(b) “Pop” is the term used to delete an element
from a stack.
PUSH OPERATION
 Step 1 − Checks if the stack is full.
 Step 2 − If the stack is full, produces an

error and exit.


 Step 3 − If the stack is not full,

increments top to point next empty space.


 Step 4 − Adds data element to the stack

location, where top is pointing.


 Step 5 − Returns success.
A Pop operation may involve the following
steps −
Step 1 − Checks if the stack is empty.
Step 2 − If the stack is empty, produces an
error and exit.
Step 3 − If the stack is not empty, accesses
the data element at which top is pointing.
Step 4 − Decreases the value of top by 1.
Step 5 − Returns success.
NOTATION
The way to write arithmetic expression is known as
a notation. An arithmetic expression can be written in
three different but equivalent notations. These notations
are −
1. Infix Notation

2. Prefix (Polish) Notation

3. Postfix (Reverse-Polish) Notation

These notations are named as how they use operator in


expression.
INFIX NOTATION

 Infix Notation
 We write expression in infix notation, e.g. a - b + c,
where operators are used in-between operands.
 It is easy for us humans to read, write, and speak in infix
notation but the same does not go well with computing
devices.
 An algorithm to process infix notation could be difficult
and costly in terms of time and space consumption.
PREFIX NOTATION

 Prefix Notation
 In this notation, operator is prefixed to operands, i.e.
operator is written ahead of operands. For example, +ab.
 This is equivalent to its infix notation a + b.
 Prefix notation is also known as Polish Notation.
POSTFIX NOTATION

Postfix Notation
 This notation style is known as Reversed Polish

Notation.
 In this notation style, the operator is postfixed to the

operands i.e., the operator is written after the operands.


 For example, ab+. This is equivalent to its infix

notation a + b.
 A queue is a linear list of elements in which deletions
can take place only at one end, called the front, and
insertions can take place only at the other end, called the
rear.
 The terms “front” and “rear” are used in describing a

linear list only when it is implemented as a queue.


 Queues are also called first-in first-out (FIFO) lists, since

the first element in a queue will be the first element out


of the queue.
 This contrasts with stacks, which are last-in first-out

(LIFO) lists.
APPLICATIONS OF QUEUE

There are various applications of queues discussed as


below.
I. Queues are widely used as waiting lists for a single
shared resource like printer, disk, CPU.
II. Queue are used to maintain the play list in media
players in order to add and remove the songs from the
play-list.
III. Queues are used in operating systems for handling
interrupts.
DEQUES
DEQUES A deque (pronounced either “deck” or
“dequeue”) is a linear list in which elements can be
added or removed at either end but not in the middle.
 The term deque is a contraction of the name double-

ended queue.

There are two variations of a deque—namely,


an input-restricted deque and an output-
restricted deque—which are intermediate
between a deque and a queue.
 An input-restricted deque is a deque which
allows insertions at only one end of the list
but allows deletions at both ends of the list;

 An output-restricted deque is a deque which


allows deletions at only one end of the list
but allows insertions at both ends of the list.
PRIORITY QUEUE
 A priority queue is a collection of elements such that
each element has been assigned a priority and such that
the order in which elements are deleted and processed
comes from the following rules:
(1) An element of higher priority is processed before any
element of lower priority.
(2) Two elements with the same priority are processed
according to the order in which they were added to the
queue.

You might also like