Chapter 4 Stacks and Queue
Chapter 4 Stacks and Queue
FILE ORGANIZATIONS
CHAPTER 4
STACKS AND QUEUES
TOPICS
• Stacks
• Infix, Postfix, and Infix Expressions
• Conversion of expressions
• Manual conversion
• Stack implementation
• Queues
STACKS
• Key operations;
• Clear() – clears the stack
• isEmpty() – Tests if the stack is empty
• Push(el) – adds ‘el’ to the top of the stack
• Pop() – Retrieves the top element of the stack
• topEl() – Returns the top element without removing it.
STACK USE
• Add to stack ( - (
• Add to stack ( - ((
• Add to stack [ - (([
• Remove from stack [ - ((
• Remove from stack ( - (
• Remove from stack ( -
• Add to stack { - {
• Add to stack /* - { /*
• Remove from stack */ - }
• Remove from stack } -
addingLargeNumbers()
read the numerals of the first number and store the numbers
corresponding to them on one stack;
read the numerals of the second number and store the numbers
corresponding to them another stack;
result = 0;
while at least one stack is not empty
pop a number from each nonempty stack and add them
to result;
push the unit part on the result stack;
store carry in result;
push carry on the result stack if it is not zero;
pop numbers from the result stack and display them;
SPECIAL TOPIC
on
Stack Implementation
(Refer to Chapter 4a)
QUEUES
• Key Operations;
• Clear() – Clear the queue
• isEmpty() – Check if the queue is empty
• Enqueue(el) – Add ‘el’ to end of queue
• Dequeue() – Take first element from queue
• firstEl() – Return first element without removing it.
QUEUE USE
acrosticIndicator()
while not finished
read a line of poem;
enqueue the first letter of the line;
while queue is not empty
dequeue and print a letter;