Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Linked Nodes. Write the code that will turn the \"before\" picture into the \"af

ID: 3734962 • Letter: L

Question

Linked Nodes. Write the code that will turn the "before" picture into the "after" picture 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 are NOT allowed to change any existing node's data field value. You also should not create new iatNode objects unless necessary to add new values to the chain, but you may create a single ListNode variable to refer to any existing node if you like. If a variable does not appear in the "after" picture, it doesn't matter what value it has after the changes are made. To help maximize partial credit in case you make mistakes, we suggest that you include optional comments with your code that describe the links you are trying to change, as shown in Section 7's solution code Before After list list temp Assume that you are using the tistede class as defined in lecture and section: public class Liatede public R, data: // data stored in this node public LiatNade next; // a link to the next node in the list public public ListJedeline data) .. )

Explanation / Answer

//importing required packages import java.util.Random; //class begin public class IntLinkedList { class Node { Node prev; Node next; int value; public Node(int val) { this.value = val; } } public Node head; public Node tail; private int size = 0; public void insert(int val) { Node newNode = new Node(val); if (this.head == null) { this.head = newNode; this.head.next = this.tail; } else { if (this.head.next == null) { newNode.prev = this.head; this.head.next = newNode; this.tail = newNode; } else { this.tail.next = newNode; newNode.prev = this.tail; this.tail = newNode; } } this.size++; } public int getSize() { return this.size; } public void print() { Node curNode = this.head; while (curNode != null) { System.out.println(curNode.value); curNode = curNode.next; } } public void reversePrint() { Node curNode = this.tail; while (curNode != null) { System.out.println(curNode.value); curNode = curNode.prev; } } public static void main(String args[]) { IntLinkedList ll = new IntLinkedList(); Random rand = new Random(); int testSize = 10, maxNum = 100; for(int i=0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote