Professional Documents
Culture Documents
Lecture No. 07
Stack Applications
Infix to postfix conversion Infix to prefix conversion Evaluation of prefix and postfix expressions Decimal to Binary Conversion Checking Balanced Symbols
Stack Applications
Infix to postfix conversion Infix to prefix conversion Evaluation of prefix and postfix expressions Decimal to Binary Conversion Checking Balanced Symbols
Balance Sequence
Balance Sequence
{[]} {((()))}
Un-Balanced Sequence
{[} ([[))
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
Stack
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
5+(7*9)(9-5)
5 + ( 7 * 9 ) ( 9 5 )
Operation is Successful
5+)7*9)(9-5)
5 + ) 7 * 9 ) ( 9 5 )
5+)7*9)(9-5)
5 + ) 7 * 9 ) ( 9 5 )
5+)7*9)(9-5)
5 + ) 7 * 9 ) ( 9 5 )
A Stack is LIFO (Last-In, First-Out) structure In contrast, a Queue is a FIFO (First-In, First-Out ) structure A Queue is a linear structure for which items can be only inserted at one end and removed at another end
Queue Operations
Enqueue(X)
Place X at the Rear of the Queue Remove the Front element and return it Return front element without removing it
Dequeue()
Front()
IsEmpty()
IsFull()
Implementation of Queue
front 2 8 6
rear 3
front 2 8 6
rear 3
front
rear
front
rear
front 8 6
rear 3
front
rear
front 8 6
rear 3
front
rear
front 8 6 3
rear 5
front
rear
Array Implementation
};
Constructor
QueueArray::QueueArray() { Front = -1; Rear = -1; }
Questions