Question: Java Program LinkedIntListClient.java: public class LinkedIntListClient{ public static void main (String [] args){ LinkedIntList list = new LinkedIntList(); System.out.println (Adding 1 -> 2 -> 3

Java Program

Java Program LinkedIntListClient.java: public class LinkedIntListClient{ public static void main (String []

LinkedIntListClient.java:

public class LinkedIntListClient{ public static void main (String [] args){ LinkedIntList list = new LinkedIntList(); System.out.println ("Adding 1 -> 2 -> 3 -> 4 -> null to the list... " ); list.add (1); list.add (2); list.add(3); list.add (4); System.out.println (list); System.out.println ("calling delete2ndBack... "); list.delete2ndBack(); System.out.println (list); System.out.println ("calling delete2ndBack... "); list.delete2ndBack(); System.out.println (list); System.out.println ("calling delete2ndBack... "); list.delete2ndBack(); System.out.println (list); System.out.println ("calling delete2ndBack... "); try{ list.delete2ndBack(); } catch (Exception e){ System.out.println (e); } System.out.println ("Final List : " + list); } }

LinkedIntList.java:

import java.util.*; public class LinkedIntList{ private ListNode front; public LinkedIntList (){ front = null; } public int remove(int index){ if(index == 0){ int data = front.data; front = front.next; return data; } ListNode current = front; for(int i = 0; i

Name your file LinkedIntList.java and submit on Canvas. You may download the client code from here and check your implementations: LinkedIntListClient.java D Your LinkedIntList.java has to work with the given client code. ** You should submit only the LinkedIntList.java ** (5 Points) Write a method add that appends the given value to the end of the list, Also write a toString method that returns a string, in the form of "data1 -> data2 -> ...->dataN -> null" when the list is not empty and returns "[ ]" when the list is empty. (10 Points) Write a method delete2ndBack that deletes the 2nd to last value (from the back of the list) and returns the deleted value. If the list is empty or the size is less than 2, your method should throw a NoSuchElementException For example, suppose that a variable list is as follows: front-> 1 -> 2 -> 3 -> 4 -> null the call delete2ndBack(); should rearrange the list as follows and return 3: front -> 1->2 -> 4 -> null Then the 2nd call delete 2ndBack(); should rearrange the list as follows and return 2: front -> 1 -> 4 -> null The 3rd call delete2ndBack(); should rearrange the list as follows and return 1: front -> 4 -> null Finally the 4th delete2ndBack(); should not rearrange the list and throw a NoSuchElementException. list should be as follows: front -> 4 -> null Add the methods to the LinkedIntList class we have worked in class. You may not call any. other methods of the class to solve this problem, you may not construct any new nodes, and you may not use any auxiliary data structures to solve this problem (such as array, ArrayList, Queue, String, etc.). You also may not change any data fields of the nodes. You must solve this problem by rearranging the links of the list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!