Chapter 21: Data Structures and java.util

The exercises here are taken from my forthcoming book, The Java Developer's Resource.

Quiz

  1. What's the difference between a stack and a queue?

Exercises

  1. As written the StringStack class still allows one to put non-String objects on the stack. Fix this by overriding push(Object o) so that it checks for the type of the object. If the object is not an instance of String push the o.toString() on the stack instead. Can you eliminate the check for the type of the object and just always push o.toString()? In other words, given that s is a String is s.toString() equal to s?
  2. As written the StringStack class still allows one to put non-String objects on the stack. Fix this by overriding push(Object o) so that it checks for the type of the object. If the object is not an instance of String throw a user defined exception.
  3. Modify the printtree method in Program 21.6 so that it prints the elements of the tree from largest to smallest.
  4. Add two methods to the treenode class, one that returns an Enumeration of the elements in the tree sorted from smallest to largest and another that returns an Enumeration sorted from largest to smallest.


[ Exercises | Cafe Au Lait | Books | Trade Shows | Links | FAQ | Tutorial | User Groups ]

Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
Last Modified August 20, 1996