Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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.

}

}

image text in transcribed

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions