the numbers on the left is just the number the code is at java Question 7. [18 marks in total] For all questions, use th

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

the numbers on the left is just the number the code is at java Question 7. [18 marks in total] For all questions, use th

Post by answerhappygod »

the numbers on the left is just the number the code is at
java
Question 7. [18 marks in total]For all questions, use the following definition of classNode.1 public class Node {2 public int data ;3 public Node next ;4
5 public Node ( int d ) {6 data = d ;7 next = null ;8 }9 }a. (6 marks) Draw a memory diagram to illustrate how the objectsare linkedafter the following code is executed. Clearly show the contents ofeachobject as well.1 Node g = new Node (10) ;2 Node p = new Node (20) ;3 Node m = new Node (30) ;4 Node t = new Node (40) ;5 g . next = p ;6 g . next . next = m ;7 g . next . next . next = t ;8 g . next . next . next . next = g ;9 m . next . next . data = 15;
b. (12 marks) Complete the following methods in the custom-builtlinkedlist class MyLinkedList (equal weight for each method).1. getFirst(): returns the value inside the first node in the list.Returnnull if empty.2. total(): return the sum of all the values in the list. Return 0if empty.3. (Advanced) reverse(): reverse the linked list. If the list was[10, 20,30] before calling the method, it should become [30, 20, 10] aftercallingthe method.1 public class MyLinkedList {2 private Node head ;34 public Integer getFirst () {5 return null ; // to be completed6 }78 public int total () {9 return 0; // to be completed10 }1112 public void reverse () {13 }14
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply