1 In an arraybased implementation of a stack which end of th
1) In an array-based implementation of a stack, which end of the contents of the array represents the bottom of the stack and why?
2) What is wrong with the java.util.Stack implementation of a stack?
3) Suppose the following sequence of elements are inserted into a stack and a queue in the following order: 50, 26, 32, 18, 26, 51. What is the result of three pop operations of the stack and three dequeue operations of the queue?
4) Write out the order of elements that are contained in a stack after the following operations are performed.
myStack.push(new Integer(8));
myStack.push(new Integer(6));
Integer num1 = myStack.pop();
myStack.push(new Integer(3));
myStack.push(new Integer(4));
myStack.push(new Integer(15));
myStack.push(new Integer(12));
myStack.push(new Integer(9));
myStack.pop();
myStack.pop();
myStack.pop();
myStack.push(new Integer(19));
5) Write a push method for a stack implemented as a linked structure. You may assume that the implementation has the top element of the stack referenced by a LinearNode reference top and that an integer variable count keeps track of the number of elements in the stack.
6) Write a push method for a stack implemented with an array. You may assume that the stack is referenced by an array named stack, and that there is an integer variable named count that keeps track of the number of elements in the stack. You may not assume that you have access to an expandCapacity method (meaning that your method should include code to expand the capacity of the array if it is full).
7) List the five basic operations on a stack.
8) A _________________ is a nonlinear structure in which elements are organized into a hierarchy.
9) In a radix sort, the radix refers to __________________________ .
10) A stack is the ideal collection to use when _______________________
Solution
Hi, I have answered first 4 questions.
Please repost others in separate post.
Please let me know in case of any issue.
1.
In array based implementation:
front end (from begining) part represent bottom of stack
back end (from last) part represent top of stack
because it is easy to add elements at end of the array
2.
The iterator method on java.util.Stack iterates through a Stack from the bottom up.
One would think that it should iterate as if it were popping off the top of the Stack.
3.
Sequence: = 50, 26, 32, 18, 26, 51.
POP sequence: 51, 26, 18, 32, 26, 50
Dequeue Sequence: 50, 26, 32, 18, 26, 51
4.
myStack.push(new Integer(8)); bottom- > 8 <-top
myStack.push(new Integer(6)); bottom- > 8, 6 <-top
Integer num1 = myStack.pop(); bottom- > 8 <-top
myStack.push(new Integer(3)); bottom- > 8, 3 <-top
myStack.push(new Integer(4)); bottom- > 8, 3, 4 <-top
myStack.push(new Integer(15)); bottom- > 8, 3, 4, 15 <-top
myStack.push(new Integer(12)); bottom- > 8, 3, 4, 15, 12 <-top
myStack.push(new Integer(9)); bottom- > 8, 3, 4, 15, 12, 9 <-top
myStack.pop(); bottom- > 8, 3, 4, 15 <-top
myStack.pop(); bottom- > 8, 3, 4 <-top
myStack.pop(); bottom- > 8, 3 <-top
myStack.push(new Integer(19)); bottom- > 8, 3, 19 <-top

