Data Structure & Algorithum java program Do the following: 1) Add a constructor to the class "LList" that creates a list from a given array of objects. 2) Add a method "addAll" to the "LList" class...


Data Structure & Algorithum java program


Do the following:


1) Add a constructor to the class "LList" that creates a list from a given array of objects.
2) Add a method "addAll" to the "LList" class that adds an array of items to the end of the list. The header of the method is as follows, where "T" is the generic type of the objects in the list.
3) Write a Test/Driver program that thoroughly tests all the methods in the class "LList".


number0fEntries++;<br>} else {<br>throw new Index0ut0fBoundsException (= 1) && (givenPosition <= number0fentries))="" {="" 57="" 58="" if(givenposition="=" 1)="" {="" result="firstNode" =="" firstnode.getnextnode();="" }else=""> nodeBefore = Node nodeToRemove = nodeBefore.getNextNode(); Node nodeAfter result = nodeToRemove.getData(); nodeBefore.setNextNode(nodeAfter); 59 60 61 firstNode.getData(); 62 63 64 getNodeAt (givenPosition - 1); 65 66 nodeToRemove.getNextNode(); 67 68 69 number0fEntries++; return result; } else { throw new IndexOut0fBoundsException ("Illegal position given."); 70 71 72 73 74 } 75 7660 A 77 @Override public void clear() { whlutlllAuto-aenerated method stub I. 78 79 80 81 82e A 83 84 85 @Override public T replace(int givenPosition, T newEntry) { if((givenPosition >= 1) && (givenPosition <= number0fentries))="" {=""> desiredNode = T originalEntry = desiredNode.getData(); desiredNode.setData(newEntry); return originalEntry; } else { throw new IndexOut0fBoundsException ("Illegal position given"); getNodeAt (givenPosition); 86 87 88 89 %3D 90 01 Problems @Javadoc Declaration Console X No consoles to display at this time. "/>
Extracted text: number0fEntries++; } else { throw new Index0ut0fBoundsException ("Illegal position given."); 48 49 50 51 } 52 53 54 550 A 56 @0verride public T remove (int givenPosition) { T result = null; if((givenPosition >= 1) && (givenPosition <= number0fentries))="" {="" 57="" 58="" if(givenposition="=" 1)="" {="" result="firstNode" =="" firstnode.getnextnode();="" }else=""> nodeBefore = Node nodeToRemove = nodeBefore.getNextNode(); Node nodeAfter result = nodeToRemove.getData(); nodeBefore.setNextNode(nodeAfter); 59 60 61 firstNode.getData(); 62 63 64 getNodeAt (givenPosition - 1); 65 66 nodeToRemove.getNextNode(); 67 68 69 number0fEntries++; return result; } else { throw new IndexOut0fBoundsException ("Illegal position given."); 70 71 72 73 74 } 75 7660 A 77 @Override public void clear() { whlutlllAuto-aenerated method stub I. 78 79 80 81 82e A 83 84 85 @Override public T replace(int givenPosition, T newEntry) { if((givenPosition >= 1) && (givenPosition <= number0fentries))="" {=""> desiredNode = T originalEntry = desiredNode.getData(); desiredNode.setData(newEntry); return originalEntry; } else { throw new IndexOut0fBoundsException ("Illegal position given"); getNodeAt (givenPosition); 86 87 88 89 %3D 90 01 Problems @Javadoc Declaration Console X No consoles to display at this time.
Lijava<br>44<br>A<br>3 import chapter10.ListInterface;<br>4<br>Unit13 src<br>src chapter12 O LList<T><br>►<br>o firstNode: Node<T><br>5 public class LList<T> implements ListInterface<T> {<br>6.<br>private NodeT firstNode;<br>private int number0fEntries%;<br>8<br>6.<br>public LList( {<br>firstNode = null;<br>number0fEntries = 0;<br>}<br>100<br>11<br>12<br>%3D<br>13<br>14<br>private Node<T> getNodeAt (int givenPostion) {<br>Node<T> currentNode = firstNode;<br>for (int count =<br>currentNode = currentNode.getNextNode();<br>}<br>return currentNode;<br>150<br>16<br>%3D<br>17<br>1; count < givenPostion; count++) {<br>18<br>19<br>20<br>21<br>22<br>23e<br>A 24<br>@Override<br>public void add(T newEntry) {<br>Node<T> newNode = new Node<>(newEntry);<br>if(isEmpty())<br>firstNode = newNode;<br>else {<br>Node<T> lastNode =<br>lastNode.setNextNode (neWNode);<br>25<br>26<br>27<br>28<br>29<br>30<br>31<br>32<br>33<br>34<br>35e<br>A 36<br>37<br>38<br>39<br>40<br>41<br>42<br>getNodeAt (number0fEntries);<br>number0fEntries++3;<br>I<br>@Override<br>public void add(int givenPosition, T newEntry) {<br>if(givenPosition >= 1 && (givenPosition <= number0fEntries + 1)) {<br>Node<T> newNode = new Node<>(newEntry)%3;<br>if(givenPosition = 1) {<br>newNode.setNextNode(firstNode);<br>firstNode = newNode;<br>Jelse {<br>Node<T> nodeBefore = getNodeAt (givenPosition - 1);<br>Node<T> nodeAfter = nodeBefore.getNextNode();<br>newNode.setNextNode(nodeAfter);<br>nodeBefore.setNextNode(newNode) :<br>%3D<br>43<br>44<br>%3D<br>45<br>46<br>Problems<br>@ Javadoc Declaration<br>Console X<br>No consoles to display at this time.<br>

Extracted text: Lijava 44 A 3 import chapter10.ListInterface; 4 Unit13 src src chapter12 O LList ► o firstNode: Node 5 public class LList implements ListInterface { 6. private NodeT firstNode; private int number0fEntries%; 8 6. public LList( { firstNode = null; number0fEntries = 0; } 100 11 12 %3D 13 14 private Node getNodeAt (int givenPostion) { Node currentNode = firstNode; for (int count = currentNode = currentNode.getNextNode(); } return currentNode; 150 16 %3D 17 1; count < givenpostion;="" count++)="" {="" 18="" 19="" 20="" 21="" 22="" 23e="" a="" 24="" @override="" public="" void="" add(t="" newentry)="" {=""> newNode = new Node<>(newEntry); if(isEmpty()) firstNode = newNode; else { Node lastNode = lastNode.setNextNode (neWNode); 25 26 27 28 29 30 31 32 33 34 35e A 36 37 38 39 40 41 42 getNodeAt (number0fEntries); number0fEntries++3; I @Override public void add(int givenPosition, T newEntry) { if(givenPosition >= 1 && (givenPosition <= number0fentries="" +="" 1))="" {=""> newNode = new Node<>(newEntry)%3; if(givenPosition = 1) { newNode.setNextNode(firstNode); firstNode = newNode; Jelse { Node nodeBefore = getNodeAt (givenPosition - 1); Node nodeAfter = nodeBefore.getNextNode(); newNode.setNextNode(nodeAfter); nodeBefore.setNextNode(newNode) : %3D 43 44 %3D 45 46 Problems @ Javadoc Declaration Console X No consoles to display at this time.
Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here