What advantage was obtained by implementing the List interfece

advertisement
1. What advantage was obtained by implementing the List interfece before
declaring the Stack class?
2. Suppose we define:
Quene<Integer> gueue = new LinkedList<Integer>();
Show what the LinkedList object(referenced by) queue will look like after each of
the following messages is sent
a. Queue.add (2000)
b. Queue.add(1215)
c. Queue.add(1035)
d. Queue.add(2117)
e. Queue.remove();
f. Queue.add(1999)
g. Queue.remove();
3. Re-do Ecercise 2. parts a through g, for a stack instead of a queue. Start with
Stack<Integer> stack = new Stack<Integer>();
Stack.push(2000)
4. Suppose that elements “a”, “b”, “c”, “d”, “e” are pushed, in that order, onto an
initially empty stack, which is then popped four times, and as each element is
popped, it is enqueued into an initially empty queue. If one element is then
dequeued from the queue, what is the next element to be dequeued?
5. Translate the following expressions into postfix notation:
a. x + y * z
b. (x + y) * z
c. x – y – z * (a + b)
d. (a + b) * c – (d + e * f/((g/h + i – j)* k))/r
Test your answers by running the Infix to Postfix.
6. Translate each of the expressions in Exercise 5 into prefix notation.
7. Declare and test the PureStack class with a LinkedList field.
Hint:Each of the definitions is a one-liner
8. Declare and test the PureStack class with a ArrayList field
Hint:For the sake of efficiency, the top of the stack should be at index size() – 1.
Download