![]() |
Help: Stacks and Queues as Interfaces
Help is available for each task, or you can go straight to the solution source code.
Add the methods push and pop. Push takes an Object as its argument and returns nothing. Pop has no arguments but returns an Object. Task 2Do the same for the Queue interfaceThe Queue has two methods, add and remove. Add takes an Object as its argument and returns nothing. Remove has no arguments but returns an Object. Task 3Add all necessary methods to QStack so it can implement the two interfaces.Add a Vector variable to the QStack to act as storage; initialize it with a new Vector. A constructor is not necessary, since initialization occurs automatically. Implement the push method by adding the Object to the end of the storage vector using the Vector method addElement. The end of the vector will act as the top of the stack. Implement the pop method by using available Vector methods to remove the last element of the Vector. Implement the add method by adding the Object to the end of the Vector. Implement the remove method by removing the first element of the Vector and returning it. Task 4Add a nice toString method to QStack so it will print out well.Use the Enumeration interface to iterate through the items of the Vector, printing each out. |
Copyright © 1996-1997 MageLang Institute. All Rights Reserved. |