Intermediate Object-Oriented Programming: Practice Class 09 (Week 10)
Intermediate Object-Oriented Programming: Practice Class 09 (Week 10)
//Returns name
public String getName(){...}
//Returns age
public int getAge(){...}
1
//Returns next
public Node getNext(){...}
Using the class definitions above and the following declarations, draw the state of
the linked list and
the variables
after the execution of each code fragment (the segments are executed one after the
other).
b) myList.addFirst(newNode);
temp.setNext(newNode);
newNode = null;
2
f) temp = myList.getFirst();
while (true)
{
if(temp.getNext().getName().equals(Bob)
{
temp.setNext(temp.getNext().getNext());
return;
}
else
{
temp = temp.getNext();
}
}
Task 2
becomes:
head
Zoe Peter Jill Bob Jane
9 15 5 11 7
null
Note: There are several ways to solve this problem. For your solution, try to make the
most use of the existing method of the given class.
Task 3
If we change the Node class from Task 1 so that instead of having a name and age
attribute, it has a data attribute that is an instance of a user-defined class Person, draw
a representation of the resulting linked list.