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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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++;
} 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
Node<T> nodeBefore =
Node<T> nodeToRemove = nodeBefore.getNextNode();
Node<T> 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)) {
Node<T> 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.
Transcribed Image 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 Node<T> nodeBefore = Node<T> nodeToRemove = nodeBefore.getNextNode(); Node<T> 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)) { Node<T> 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
44
A
3 import chapter10.ListInterface;
4
Unit13 src
src chapter12 O LList<T>
►
o firstNode: Node<T>
5 public class LList<T> implements ListInterface<T> {
6.
private NodeT firstNode;
private int number0fEntries%;
8
6.
public LList( {
firstNode = null;
number0fEntries = 0;
}
100
11
12
%3D
13
14
private Node<T> getNodeAt (int givenPostion) {
Node<T> 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) {
Node<T> newNode = new Node<>(newEntry);
if(isEmpty())
firstNode = newNode;
else {
Node<T> 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)) {
Node<T> newNode = new Node<>(newEntry)%3;
if(givenPosition = 1) {
newNode.setNextNode(firstNode);
firstNode = newNode;
Jelse {
Node<T> nodeBefore = getNodeAt (givenPosition - 1);
Node<T> 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.
Transcribed Image Text:Lijava 44 A 3 import chapter10.ListInterface; 4 Unit13 src src chapter12 O LList<T> ► o firstNode: Node<T> 5 public class LList<T> implements ListInterface<T> { 6. private NodeT firstNode; private int number0fEntries%; 8 6. public LList( { firstNode = null; number0fEntries = 0; } 100 11 12 %3D 13 14 private Node<T> getNodeAt (int givenPostion) { Node<T> 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) { Node<T> newNode = new Node<>(newEntry); if(isEmpty()) firstNode = newNode; else { Node<T> 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)) { Node<T> newNode = new Node<>(newEntry)%3; if(givenPosition = 1) { newNode.setNextNode(firstNode); firstNode = newNode; Jelse { Node<T> nodeBefore = getNodeAt (givenPosition - 1); Node<T> 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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY