If you are planning to use JHAVEPOP for your course (or if you just have a question), please contact David Furcy at furcyd@uwosh.edu

JHAVEPOP works great with Firefox, IE7, Safari, Opera, Konqueror, and other browsers.
Among all the browsers we tested, only IE 6 had trouble opening dynamically-generated .jnlp files.

Linked list manipulations using JHAVEPOP


Overview

The first 20 exercises on this page are quite short. They will help you master basic linked list operations. The last 5 programming assignments are more challenging. They will help you become comfortable designing and implementing robust algorithms to manipulate linked lists. Before attempting the exercises, you should take the time to read the following overview of JHAVEPOP carefully.

JHAVEPOP allows you to view the contents of memory as your program executes. When you feed some Java code as input to JHAVEPOP, it automatically generates a sequence of snapshots. A snapshot depicts the value of all variables in memory after each statement of your program is executed. Therefore, JHAVEPOP makes it easier to test and debug your programs.

How to use JHAVEPOP
  1. Read and understand the exercise fully.
  2. Design your program on paper, then type your code in your favorite text editor.
  3. Paste your code into JHAVEPOP to see the visualization. That is, when your code is ready to test, click on the red button to launch JHAVEPOP (there is one button for each exercise or test case). Wait until the window asking you to paste your code pops up. This window will already contain three or more lines of code. Do not modify these lines (they are there to create the initial setup for the exercise). Simply paste your code below these lines and click OK.

    That's it!

    The first snapshot will be visible. Under it, you'll find controls to navigate from one snapshot to the next and back. In the right pane, your code will appear highlighted as it gets executed. You can also click the "Info" tab (top right) to find out more about JHAVEPOP.
  4. If you detect an error in your code, use the visualization to help you fix and edit your code in your favorite text editor. When you are ready to test it again, click on the "Setup" tab (top left of the JHAVEPOP window) and then the "Visualize" button (bottom right). You are now ready to paste your new code.
  5. Finally, when you are done working on the exercise, close the JHAVEPOP window by clicking the X in the top-right corner. You will be back on this page and ready to work on another exercise.
How to write your Java code

JHAVEPOP contains an interpreter for Java. The interpreter has a built-in class called Node with two public instance variables: info of type 'char', and next of type 'Node'. This class implements a node in a singly-linked list. Because it focuses on operations on linked lists, JHAVEPOP's interpreter only supports a sub-set of the Java language, namely assignment statements, if statements, while and for loops. The following examples illustrate the range of acceptable constructs:

Construct Examples
1. Assignment
n1 = n4.next; n1.next = null;
2. Node instantiation
n3.next.next = new Node('B',null);
3. Assignment
n1.info = n4.next.info; n1.next.info = 'C';
4. If statement
if (n1==null) {...} else {...}
5. While loop
while ( (n1!=null) && (n1.info=='A') ) {...}
6. For loop
for( n1=n2; n1!=null; n1=n1.next ) {...}
7. Break statement
break;


Keep in mind that ALL blocks within if statements or loops must always be surrounded by braces { }, even when the block contains only one statement. Of course, if statements and loops require boolean expressions, which must be fully parenthesized. Boolean expressions may compare the values of Node reference variables, the values of the info instance variable, or 'char' literals such as 'A', '1', etc. Simple boolean expressions may be combined into compound boolean expressions with the logical operators '&&' or '| |'. However, each boolean expression may NOT contain more than one such operator. That is, a compound boolean expression may combine only two simple boolean expressions.

JHAVEPOP does NOT support: Even though JHAVEPOP allows you to declare any number of Node reference variables at the top level of your code (but not within a block), you should NOT declare any variable for any of the following exercises and assignments.

Short exercises



ExerciseInitial SetupFinal Configuration
1 Use a single assignment statement to make the variable p refer to the Node with info '2'.
Ready to solve it?

2 Redo exercise 1 but, this time, your assignment statement must refer to both variables p and q.
Ready to solve it?

3 Use a single assignment statement to make the variable q refer to the Node with info '1'.
Ready to solve it?

4 Use a single assignment statement to make the variable r refer to the Node with info '2'.
Ready to solve it?

5 Use a single assignment statement to set the info of the Node referred to by p equal to the info of the Node referred to by r (you must access this info through r; do not refer to the character '3' directly).
Ready to solve it?

6 Redo exercise 5 by referring only to variable p (not to variable r). Again, you may not refer to the character '3' directly .
Ready to solve it?

7 Write a single assignment statement to transform the linked list headed by p into a circular linked list. Your assignment statement must refer to both variables p and r.
Ready to solve it?

8 Redo exercise 7 but, this time, your assignment statement must refer to both variables p and q.
Ready to solve it?

9 Redo exercise 7 but, this time, your assignment statement must refer only to variable p.
Ready to solve it?

10 Write a single assignment statement to remove the Node with info 'B' from the linked list headed by p. Your assignment statement must refer to both variables p and q.
Ready to solve it?

11 Write a single assignment statement to remove the Node with info 'B' from the linked list headed by p.
Ready to solve it?

12 Write a while loop to make q refer successively to each Node in the linked list headed by p. q must end up referring to the last Node in the list.
Ready to solve it?

13 Write a while loop to make q refer successively to each Node in the linked list headed by p until q refers to the first Node with info (lowercase) 'c'.
Ready to solve it?

14 Use four assignment statements, each referring to variable p, to create a linked list headed by p and containing 4 Nodes with info 'A', 'B', 'C', and 'D', in this order.
Ready to solve it?

15 Create a new Node with info 'A' and insert it at the beginning of the list headed by p.
Ready to solve it?

16 Create a new Node with info 'D' and insert it at the end of the list headed by p.
Ready to solve it?

17 Remove the Node at the beginning of the list headed by p and insert it at the end of the same list. Your program must refer to both variables p and q.
Ready to solve it?

18 Redo exercise 17 but, this time, your program must only refer to variable p.
Ready to solve it?

19 Merge the two lists headed by p and q into a single list headed by p in which the Nodes are sorted in alphabetical order.
Ready to solve it?

20 Using only the three existing variables p, q, and r, reverse the order of the Nodes in the list headed by p.
Ready to solve it?



Programming assignments