Consider a Single Linked List (SLL) of nodes, where ‘node’ is a type with two fields: integer data and the node type reference ‘next’ that refers to the next node in the list. For each part given below consider the SLL and the code given in the second column. Following the execution of the code, show the resulting list (in the answer box, for each part, use the arrow key to draw the list as: head-----> ? -------> ? --------> ?).
List and Java Code
a
head⟶1⟶2⟶3⟶4⟶null
node ptr=head;
node newnode = new node(0); // data=0
head = newnode;
newnode.next=ptr;
b
node newnode = new node(6); // data=6
while(ptr.next!=null) {
ptr=ptr.next;
}
ptr.next=newode;
c
head=ptr;
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here