Tute1 Stacks
Tute1 Stacks
Year 2
Data Structures and Algorithms – IT2070
Tutorial 1 - Stacks
2024
Question 1
a) Consider the following Stack and draw the Stack frames after executing each statement given below.
i) theStack.push(2);
ii) theStack.push(a);
iii) theStack.push(a + b);
iv) theStack.pop();
v) theStack.push(b);
vi) theStack.push(a –b );
Question 2
1
Question 3
public StackX()
{
stArr = new double[10];
maxSize = 10;
top = -1;
}
Question 4
i. A stack class has already been implemented with push() , pop() and peek() methods. It is
a. used to store characters. Write a code segment to insert following characters to a
’myStack’ object created from the stack class.
b. ‘g’ , ‘t’, ‘o’, ‘p’
ii. Write code segment to display all the values in a stack by removing them.
iii. What is the result of section ii) above?
Question 5
2
Question 6
5 Top
Below stack frames are obtained after executing three operations one after another to the above stack
frame. Write down the operations.
8 Top 8 Top