Question
Write the implementation for a linked list of integers (modify/adapt for int the generic implementation discussed in class). Have the following: //Interface: LinkedListIntADT public interface
Write the implementation for a linked list of integers (modify/adapt for int the generic implementation discussed in class). Have the following: //Interface: LinkedListIntADT public interface LinkedListIntADT { public boolean isEmptyList(); public void initializeList(); public void print(); public int length(); public int front(); public int back(); public boolean search(int searchItem); public void insertFirst(int newItem); public void insertLast(int newItem); public void deleteNode(int deleteItem); }
//Class: LinkedListIntClass implements //Interface: LinkedListIntADT import java.util.*; public abstract class LinkedListIntClass implements LinkedListIntADT { ... }
//Class: UnorderedLinkedListInt extends //Class: LinkedListIntClass public class UnorderedLinkedListInt extends LinkedListIntClass {
... }
2. Add to the class UnorderedLinkedListInt a value-returning member method named findSum that returns the sum of all the data values in a list. Work with the above list of integers (int).
3. Add to the class UnorderedLinkedListInt a value-returning member method named findMin that returns the smallest of all the data values in a list. Work with the above list of integers (int).
4. Add to the class UnorderedLinkedListInt a toString method to create a comma-separated, bracketed version of the list (as in the sample output below). Work with the above list of integers (int).
5. Test the new methods using the client below. Handle input validation.
//Class: ClientUnorderedLinkedListInt //Input: 37 10 88 59 27 20 14 32 89 100 12 999 import java.util.*; public class ClientUnorderedLinkedListInt { public static void main(String[] args) { Scanner input = new Scanner(System.in);
UnorderedLinkedListInt intList = new UnorderedLinkedListInt(); UnorderedLinkedListInt tempList; int num; System.out.println("Enter integers (999 to stop)"); num = input.nextInt();//valid?? while (num != 999) { intList.insertLast((Integer) num); num = input.nextInt();//valid?? } System.out.print(" Testing .insertLast and .print. The original list is: "); intList.print(); System.out.println(" Testing .length. The length of the list is: " + intList.length()); if (!intList.isEmptyList()) { System.out.println("Testing .front. First element/list: " + intList.front()); System.out.println("Testing .back. Last element/list: " + intList.back()); } System.out.println("Testing .sum. The sum of data in all nodes is: " + intList.findSum()); System.out.println("Testing .min. The smallest data in all nodes is: " + intList.findMin()); System.out.print("Testing .search. Enter the number to search for/list: "); num = input.nextInt(); //valid?? if (intList.search(num)) System.out.println(num + " found in this list."); else System.out.println(num + " is not in this list."); System.out.print("Testing .remove. Enter the number to be deleted from list: "); num = input.nextInt();//valid?? intList.deleteNode(num); System.out.print("Testing .toString. After deleting " + num + ", the list is: " + intList); System.out.println(" The length of the list after delete is: " + intList.length());
//Optional: add more testing here } // add methods for input validation } OUTPUT: Enter integers (999 to stop) 37 10 88 59 27 20 14 32 89 100 12 999 Testing .insertLast and .print. The original list is: 37 10 88 59 27 20 14 32 89 100 12 Testing .length. The length of the list is: 11 Testing .front. First element/list: 37 Testing .back. Last element/list: 12 Testing .sum. The sum of data in all nodes is: 488 Testing .min. The smallest data in all nodes is: 10 Testing .search. Enter the number to search for/list: 20 20 found in this list. Testing .remove. Enter the number to be deleted from list: 59 Testing .toString. After deleting 59, the list is: [37, 10, 88, 27, 20, 14, 32, 89, 100, 12] The length of the list after delete is: 10
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started