Question: Please help me with this questions! I really need help. thank you in advance!! useful info to debug the code! // Class LinkedIntList can be

Please help me with this questions! I really need help. thank you in advance!!

Please help me with this questions! I really need help. thank you

useful info to debug the code!

// Class LinkedIntList can be used to store a list of integers.

public class LinkedIntList {

private ListNode front; // first value in the list

// post: constructs an empty list

public LinkedIntList() {

front = null;

}

// post: returns the current number of elements in the list

public int size() {

int count = 0;

ListNode current = front;

while (current != null) {

current = current.next;

count++;

}

return count;

}

// pre : 0

// post: returns the integer at the given index in the list

public int get(int index) {

return nodeAt(index).data;

}

// post: creates a comma-separated, bracketed version of the list

public String toString() {

if (front == null) {

return "[]";

} else {

String result = "[" + front.data;

ListNode current = front.next;

while (current != null) {

result += ", " + current.data;

current = current.next;

}

result += "]";

return result;

}

}

// post : returns the position of the first occurrence of the given

// value (-1 if not found)

public int indexOf(int value) {

int index = 0;

ListNode current = front;

while (current != null) {

if (current.data == value) {

return index;

}

index++;

current = current.next;

}

return -1;

}

// post: appends the given value to the end of the list

public void add(int value) {

if (front == null) {

front = new ListNode(value);

} else {

ListNode current = front;

while (current.next != null) {

current = current.next;

}

current.next = new ListNode(value);

}

}

// pre: 0

// post: inserts the given value at the given index

public void add(int index, int value) {

if (index == 0) {

front = new ListNode(value, front);

} else {

ListNode current = nodeAt(index - 1);

current.next = new ListNode(value, current.next);

}

}

// pre : 0

// post: removes value at the given index

public void remove(int index) {

if (index == 0) {

front = front.next;

} else {

ListNode current = nodeAt(index - 1);

current.next = current.next.next;

}

}

// pre : 0

// post: returns a reference to the node at the given index

private ListNode nodeAt(int index) {

ListNode current = front;

for (int i = 0; i

current = current.next;

}

return current;

}

}

and the test code!!

// Code to post with Quiz16 public class Post { public static void main(String[] args) { LinkedIntList intList = new LinkedIntList(); System.out.println(intList.isPerfectStutter()); // false intList.add(1); intList.add(1); intList.add(2); intList.add(2); System.out.println(intList); // [1, 1, 2, 2] System.out.println(intList.isPerfectStutter()); // true intList.undoStutter(); System.out.println(intList); // [1, 2] } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!