Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please answer the questions below in the screenshot. Given code: import java.lang.AssertionError; public class MyLinkedList { class Node { / / FIXME add member variables
Please answer the questions below in the screenshot.
Given code:
import java.lang.AssertionError;
public class MyLinkedList
class Node
FIXME add member variables
NodeT data Node inherits T from MyLinkedList
FIXME
FIXME add member variables
Construct an MyLinkedList.
public MyLinkedList
FIXME
Return the number of elements in the MyLinkedList.
@return The number of elements in the MyLinkedList.
public int size
return ; FIXME
Add an element to the end of the MyLinkedList.
@param element The element to add.
public void addT element
FIXME
Get the element at the specified index.
This function assumes that the index argument is within range of the MyLinkedList.
@param index The index to get.
@return The element at the specified index.
public T getint index
return null; FIXME
Remove the element at the specified index.
This function assumes that the index argument is within range of the MyLinkedList.
@param index The index to remove.
public void removeint index
FIXME
Create a String representation of the MyLinkedList.
@return A String representation of the MyLinkedList.
public String toString
String result ;
if thissize
result this.get;
for int i ; i this.size; i
result this.geti;
result ;
return result;
Check that an MyLinkedList contains the same elements as an int array.
If the list and the array are not the same, throw an AssertionError.
@param list The MyLinkedList to check.
@param answer The expected answer, in the form of an int array.
public static void assertArraysEqualMyLinkedList list, int answer
if listsize answer.length
throw new AssertionErrorExpected list of length answer.length but got list.size;
for int i ; i answer.length; i
if Integerlistgeti answeri
throw new AssertionErrorExpected answeri but got list.geti at index i;
Test that the empty arraylist has size
public static void test
MyLinkedList list new MyLinkedList;
int answer new int;
assertArraysEquallist answer;
Test insertion into an arraylist without resizing
public static void test
MyLinkedList list new MyLinkedList;
for int i ; i ; i
list.addi i;
int answer ;
assertArraysEquallist answer;
Test deletion from an arraylist without emptying it
public static void test
MyLinkedList list new MyLinkedList;
for int i ; i ; i
list.addi i;
list.remove;
list.remove;
int answer ;
MyLinkedList.assertArraysEquallist answer;
Test deletion from an arraylist and emptying it
public static void test
MyLinkedList list new MyLinkedList;
for int i ; i ; i
list.addi i;
list.remove;
list.remove;
delete the final remaining numbers
list.remove;
list.remove;
list.remove;
int answer;
MyLinkedList.assertArraysEquallist answer;
check that there are no lastelement issues
for int i ; i ; i
list.addi i;
list.remove;
list.add;
int answer;
MyLinkedList.assertArraysEquallist answer;
Test insertion into an arraylist with resizing
public static void test
MyLinkedList list new MyLinkedList;
for int i ; i ; i
list.addi i;
int answer ;
MyLinkedList.assertArraysEquallist answer;
Put the MyLinkedList through some simple tests.
@param args Ignored command line arguments.
public static void mainString args
test;
test;
test;
test;
test;
System.out.printlnpass;
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