List Worksheet


  1. Given the following picture of a linked list, where Head and Ptr are of type LLNode<String>:

    Write the code that will manipulate the linked list as follows. Each question should use the original list shown above.

    1. Make Ptr point to the node containing the String "Right".
    2. Make Ptr point to the node containing the String "Up".
    3. Make Ptr point to the node containing the String "Down".
    4. Make the node containing the String "Up" point to the node containing the String "Left".
    5. Make the node containing the String "Right" point to itself.
    6. Make the node containing the String "Down" point to the node containing the String "Up".
    7. Change the node containing the String "Left" to contain the String "South".

  2. Suppose a, b, and c are declared as type LLNode<Integer>. Show what is printed for the following:
         a = new LLNode<Integer>();
         a.setInfo(10);
         b = new LLNode<Integer>();
         b.setInfo(20);
         a.setLink(b);
         c = new LLNode<Integer>();
         c.setInfo(a.getInfo() + b.getInfo());
         b.setLink(c);
         System.out.println(a.getInfo() + " " + c.getInfo()
                                      + " " + a.getLink().getInfo();
    


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2012