Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using these testers: public static void task2Test() { System.out.println( task2Test; add(E e, int i) method); System.out.println(****************************); DoublyLinkedList dll = new DoublyLinkedList(); dll.add(b); dll.add(c); dll.add(d); System.out.println(added

image text in transcribed

image text in transcribedimage text in transcribed

Using these testers:

public static void task2Test() {

System.out.println(" task2Test; add(E e, int i) method");

System.out.println("****************************");

DoublyLinkedList dll = new DoublyLinkedList();

dll.add("b");

dll.add("c");

dll.add("d");

System.out.println("added b,c,d:");

System.out.println(dll);

System.out.println("size: " + dll.size());

System.out.println("****************************");

try {

dll.add("d", -1);

} catch (IndexOutOfBoundsException e){

System.out.println("Exception caught adding at i=-1: " + e.getMessage());

}

try {

dll.add("d", dll.size()+1);

} catch (IndexOutOfBoundsException e){

System.out.println("Exception caught adding at i=size+1: " + e.getMessage());

}

dll.add("a", 0);

dll.add("e", dll.size());

System.out.println("****************************");

System.out.println("after add(e, i) method was called at [0] and [size]: " + dll);

System.out.println("size: " + dll.size());

System.out.println("****************************");

}

public static void task3Test() {

System.out.println(" task3Test; remove(int i) method");

System.out.println("****************************");

DoublyLinkedList dll = new DoublyLinkedList();

dll.add("b");

dll.add("c");

dll.add("d");

System.out.println("added b,c,d:");

System.out.println(dll);

System.out.println("size: " + dll.size());

System.out.println("****************************");

try {

dll.add("d", -1);

} catch (IndexOutOfBoundsException e){

System.out.println("Exception caught adding at i=-1: " + e.getMessage());

}

try {

dll.add("d", dll.size()+1);

} catch (IndexOutOfBoundsException e){

System.out.println("Exception caught adding at i=size+1: " + e.getMessage());

}

dll.add("before a", 0);

dll.add("e", dll.size());

System.out.println("****************************");

System.out.println("after add(e, i) method was called at [0] and [size]: " + dll);

System.out.println("size: " + dll.size());

System.out.println("****************************");

try {

dll.remove(-1);

} catch (IndexOutOfBoundsException e){

System.out.println("Exception caught removing at i=-1: " + e.getMessage());

}

try {

dll.remove(dll.size());

} catch (IndexOutOfBoundsException e){

System.out.println("Exception caught removing at i=size: " + e.getMessage());

}

dll.remove(0);

dll.remove(dll.size() - 1);

System.out.println("****************************");

System.out.println("after remove(i) method was called at [0] and [size-1]: " + dll);

System.out.println("size: " + dll.size());

}

2) Add an add (E e, int i) method to the DoublyLinkedlist class. What is the run time of this method? Throw an exception if i is an invalid index. (i must be >= 0 and

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

Step: 3

blur-text-image

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

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions