Question: For the class SimpleLinkedList2 given to you in Lec#7 (folder: Lec7-Code/linkedlist_demo), write a method: public int getTotal() The method sums up all integer values in
For the class SimpleLinkedList2 given to you in Lec#7 (folder: Lec7-Code/linkedlist_demo), write a method: public int getTotal() The method sums up all integer values in the calling object of SimpleLinkedList2 and returns the sum. Your code CANNOT call any other methods in this class or any other class. It means that you have to implement it from scratch and walk down the list of Nodes in-person. Hint: Your code is inside the class SimpleLinkedList2 and has direct access to the data fields in the calling object of SimpleLinkedList2.
/* ConnectNodesDemo.java * Demo how to connect nodes indirectly outside class SingleLinkedList
import linkedlist_generic.SingleLinkedList;
public class ConnectNodesDemo { public static void main(String[] args) { SingleLinkedList
/* This file is what I demoed in class. * The gneneric single linked list class. */ package linkedlist_generic_demo;
public class SingleLinkedList
//create a new standalone node without anything following the node public Node(E data) { this.data = data; next = null; }
//create a new node and place it immediately before the node referenced by variable next public Node(E data, Node
} private Node
//connect Node objects direcctly tom.next = henry; henry.next = harry; harry.next = sam;
System.out.println("pause"); //connect Node objects directly Node
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
