Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Program -- the file's name must be LinkedIntList.java LinkedIntListClient.java: public class LinkedIntListClient{ public static void main (String [] args){ LinkedIntList list = new LinkedIntList();

Java Program -- the file's name must be LinkedIntList.java

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

How do people at work stake their claim on a particular territory?

Answered: 1 week ago