I need help on problems 9-12. Java uilding Java Programs 3 x MC Chegg Study I Gu
ID: 3853748 • Letter: I
Question
I need help on problems 9-12.
Java
uilding Java Programs 3 x MC Chegg Study I Guided solu x VLMy Drive Google Drive x C https://drive.google.com/drivelmy drive For each of the next four problems, draw a picture of what the given linked nodes would look like after the given code executes, 5. list. list. next a new Li 6. list list next new Link Node list, next 7. list. 1 list new Link Node 4 list next next list, null For each of the next nine problems, you'll see pictures of linked nodes before and after changes. Write the code that will produce the given result by modifying links between the nodes shown and/or creating new nodes as needed. There may be more than one way to write the code. but you may not change any existing node's data field value. If a variable does not appear in the "after" picture. it doesn't matter what value it has after the changes are made. After 9. list. 1 list 1 10. list. list 11. list, 1 --2 list temp 3 4 12. list 1 list. list 1 3 t2 13. list 5 list 4 5 3 14. list list 3 4 5 15. list. listExplanation / Answer
9)answer:
here new node 3 is added at end of the list, the list already have 2 nodes, so need to traverse them, to add node at the end ..
now list is varible which points to first node 1(data),
in node 1, the next variable will points to node 2(data),
in node 2, the next variable is null, because this is end, so , we have to create a new node (where data initializes to 3),and assign it address to , node 2 's next variable
code:
(java)
list.next.next = new LinkedNode(3);
//this will create new node and assigns its data 3, and pointed by second node next variable
10)answer:
//take new variable T
//now create node
T = new LinkedNode(3)//new node initialzed with value 3
T.next = list; //linking remaing list
list = T;//pointing list to head which is 3
11)answer:
temp.next.next = list.next;//pointing 2 to next variable of 4
list.next = temp;//pointing 3 to next variable of 1
12)answer:
list2 = list;//pointing list2 to head of list1
list= list.next//pointing list to node 2
list2.next = null;//removing head, now list and list2 are seperated
//list points the node with value 2
//list2 points the node with value 1
/now have to add a new node with value 3 to list2
list2.next = new LinkedNode(3);//new node added to list2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.