Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA PLEASE Exercise 1 Create void deletion(int index) method within ListWithLin

ID: 3715634 • Letter: J

Question

JAVA PLEASE

Exercise 1

Create void deletion(int index) method within ListWithLinks file

Before you delete the node, print “Deleting...” + address of node-to-be-delete

OR make the method return the address

Create printEveryOther() method to print data from every other node

   i.e. list = [‘a’, ‘b’, ‘c’, ‘d’] returns [‘a’, ‘c’]

   No return value, no input passed in as parameter

Test it in Lab8Ex1.java file ... test cases on slide, submit both edited ListWithLinks file and Lab8Ex1 file*

ListWithLinks file

class ListItem {

String data;

ListItem next;

}

public class ListWithLinks2 {

// Instance variables.

ListItem front = null;

ListItem rear = null;

// To keep track of the size.

int numItems = 0;

public void add (String s)

{

   if (front == null) {

// The special case of an empty list needs to be handled differently.

      front = new ListItem ();

      front.data = s;

      rear = front;

      rear.next = null;

   }

   else {

// Just like before:

ListItem nextOne = new ListItem ();

      nextOne.data = s;

      rear.next = nextOne;

      rear = nextOne;

   }

   numItems ++;

}

public int size ()

{

   return numItems;

}

  

public String get (int i)

{

   if (i >= numItems) {

      return null;

   }

// Otherwise, count up to the i-th item.

   int count = 0;

   ListItem listPtr = front;

   while (count < i) {

      listPtr = listPtr.next;

      count ++;

   }

   return listPtr.data;

}

public boolean contains (String s)

{

   if (front == null) {

      return false;

   }

// Start from the front and walk down the list. If it's there,

// we'll be able to return true from inside the loop.

   ListItem listPtr = front;

   while (listPtr != null) {

      if ( listPtr.data.equals(s) ) {

       return true;

      }

      listPtr = listPtr.next;

   }

   return false;

}

public void printList ()

{

// INSERT YOUR CODE HERE.

}

}

Test Cases 1 Add 5. printEveryOther a. To empty list b. To any list with> 1 element a. From empty list b. From full list with odd elements C. From full list with even elements 2. Size a. Of empty list b. Of full list 3. Get 6. Reverse a. b. c. From empty list From invalid i value From any full list with valid i d. From empty list e. From full list f. From list with one element Contains a. b. c. From empty list From full list without the element From full list with the element

Explanation / Answer

Hi Dear,

Please find my implementation of printEveryOther() method.

Output:

a c e

Process finished with exit code 0