Description
This lab focuses on the fundamental mechanics of using singly- and doubly-linked nodes as containers for physical storage. After completing the lab you should
- Understand creation and linking of singly-linked nodes.
- Understand creation and linking of doubly-linked nodes.
(This document is available outside of Canvas here.)
Set-up
- Open the
COMP2210/labs
directory on your Engineering H: drive. (If you didn’t complete the previous lab where you created this directory structure, do so now.) - Create the
lab08
directory. - Download the zip file associated with this lab, store it in the
COMP2210/labs/lab08
directory, and unzip the file. - Open jGRASP to the
lab08
directory.
Singly-linked nodes
- Open
SinglyLinked.java
in jGRASP and compile it. - Set a breakpoint on line 18:
client.basicExamples();
- Start the debugger and wait until execution is paused at the breakpoint.
- Step in to the call to
basicExamples()
. - Single-step to line 54:
n = new Node(1);
- Open a viewer on
n
. - Step over each remaining statement in
basicExamples
, making sure you understand the effect of each statement. (You may want to step in to the calls tolength
andcontains
.)
Close the viewer and end program execution.
- Clear any previous breakpoints you set in
SinglyLinked.java
. - Set a breakpoint on line 19:
client.add()
. - Start the debugger and wait until execution is paused at the breakpoint.
- Step in to the call to
add()
. - Single-step to line 142:
System.out.println(toString(n));
- Open a viewer on
n
. - Click on the Interactions tab in the jGRASP Desktop.
- Use Interactions to practice inserting the node referenced by
temp
at various locations in the pointer chain. (You’ll have to repeat these steps each time you want to practice an insertion.)
Close the viewer and end program execution.
- Clear any previous breakpoints you set in
SinglyLinked.java
. - Set a breakpoint on line 20:
client.delete()
. - Start the debugger and wait until execution is paused at the breakpoint.
- Step in to the call to
delete()
. - Single-step to line 157:
System.out.println(toString(n));
- Open a viewer on
n
. - Click on the Interactions tab in the jGRASP Desktop.
- Use Interactions to practice deleting various nodes in the pointer chain. (You may have to repeat these steps when you want to practice multiple deletions.)
Close the viewer and end program execution.
Doubly-linked nodes
- Open
DoublyLinked.java
in jGRASP and compile it. - Set a breakpoint on line 18:
client.basicExamples();
- Start the debugger and wait until execution is paused at the breakpoint.
- Step in to the call to
basicExamples()
. - Single-step to line 52:
m = new Node(2);
- Open a viewer on
n
. - Step over each remaining statement in
basicExamples
, making sure you understand the effect of each statement. (You may want to step in to the calls tolength
andcontains
.)
Close the viewer and end program execution.
- Clear any previous breakpoints you set in
DoublyLinked.java
. - Set a breakpoint on line 19:
client.add()
. - Start the debugger and wait until execution is paused at the breakpoint.
- Step in to the call to
add()
. - Single-step to line 138:
System.out.println(toString(n));
- Open a viewer on
n
. - Click on the Interactions tab in the jGRASP Desktop.
- Use Interactions to practice inserting the node referenced by
temp
at various locations in the pointer chain. (You’ll have to repeat these steps each time you want to practice an insertion.)
Close the viewer and end program execution.
- Clear any previous breakpoints you set in
DoublyLinked.java
. - Set a breakpoint on line 20:
client.delete()
. - Start the debugger and wait until execution is paused at the breakpoint.
- Step in to the call to
delete()
. - Single-step to line 156:
System.out.println(toString(n));
- Open a viewer on
n
. - Click on the Interactions tab in the jGRASP Desktop.
- Use Interactions to practice deleting various nodes in the pointer chain. (You may have to repeat these steps when you want to practice multiple deletions.)
Close the viewer and end program execution.