Lab: Questions About Stacks and Queues


Instructions: Answer as many of the following questions as you can during the lab period. If you are unable to complete the assignment during the lab period it is strongly recommended that you complete it on your own.

You must submit hardcopy of your answers by 5:00PM (on the day of the lab).

Getting Ready: Before going any further, you should:

  1. Make a directory for this lab.
  2. Setup your development environment.
  3. Download the following files:
    to your working directory. (In most browsers, the easiest way to do this is by right-clicking on each of the links above.)

1. Basics: This part of the lab will help you determine whether you understand some of the basic issues involving linked data structures.
  1. Draw a model of an IntNode that contains the value 5.

  2. Draw a model of a Node that contains a reference to a String containing "JMU".

  3. Draw a model of what memory looks like after the following is executed:
        Pile            pile;
      
        pile = new Pile();
        

  4. Continuing with this same example, now draw a model of what memory looks like after the following is executed:
        pile.push(10);
        

  5. Continuing with this same example, now draw a model of what memory looks like after the following is executed:
        pile.push(20);
        

  6. Continuing with this same example, now draw a model of what memory looks like after the following is executed:
        pile.push(30);
        

2. More Complicated Linked Structures: This part of the lab will help you determine whether you understand more complicated linked data structures.
  1. Draw a model of what memory looks like after the following is executed:
        Quack            quack;
      
        quack = new Quack();
        

  2. Continuing with this same example, now draw a model of what memory looks like after the following is executed:
        quack.push("I");
        

  3. Continuing with this same example, now draw a model of what memory looks like after the following is executed:
        quack.push("like");
        

  4. Continuing with this same example, now draw a model of what memory looks like after the following is executed:
        quack.push("ducks");
        

  5. Continuing with this same example, now draw a model of what memory looks like after the following is executed:
        quack.pep();
        

  6. Continuing with this same example, now draw a model of what memory looks like after the following is executed:
        quack.pep();
        

  7. Continuing with this same example, now draw a model of what memory looks like after the following is executed:
        quack.pep();
        

  8. Trace the execution of the main() method in the QuackDriver class. [Note: This example uses the pip() method in the Quack class, not the pep() method.]

Copyright 2007