Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The first question is a Linked List question, A->E answsers(5) Second is Recursion A-C (3) A . Assume in this LL that you always remove

The first question is a Linked List question, A->E answsers(5) Second is Recursion A-C (3)

image text in transcribed

A. Assume in this LL that you always remove from the front of the list. In the method provided remove Slimy assume next and prev are public variables that you dont need a method to access, give the code to show the removal:

public void delete()

{

}

B.This time in the linked list insert a new node in the second position, leaving the first node the same, dont need to worry about an empty list. In the method provided below Insert the Node TEA after the Node Dirty (Because you already did step A, Slimy should be removed) assume next and prev are public variables that you dont need a method to access:

public void insert()

{

Node ref = new Node(TEA);

}

C. Now assume the delete End method below always removes from the end of the list In the method provided remove TMZ assume next and prev are public variables that you dont need a method to access, and the linked list diagram should be updated with the steps from questions A, and B above:

public void deleteEnd()

{

}

D. Assume in this linked list that now you need to add a new node at the end of the list. In the method provided below Insert the Node Donkey after the last Node in the list assume next and prev are public variables that you dont need a method to access the references:

public void insert()

{

Node ref = new Node(Donkey);

}

E. Redraw the list with all the updates (A->D) above. Use the graphic above as a reference on how to draw the list, show all the nodes, what all prev and next are referencing as well as first and last.

Recursion

Consider the following three functions defined recursively:

void mystery1(int n)

{

if (n == 1)

System.out.println(n);

else

{

System.out.println(n);

mystery1(n-1);

mystery1(n-1);

}

}

void mystery2(int n)

{

if (n == 1)

System.out.println(n);

else

{

mystery2(n-1);

System.out.println(n);

mystery2(n-1);

}

}

void mystery3(int n)

{

if (n == 1)

System.out.println(n);

else

{

mystery3(n-1);

mystery3(n-1);

System.out.println(n);

}

}

What is the output for the following (no errors, in same instance so no instance reference needed.....the method call works, the method works):

A.mystery1(4);

B.mystery2(4);

C.mystery3(4)

QUESTION 1 Linked List-Giving the following linked list diagram: Node last first name "Rumor" next = prev Node Node name-"Dirty" next name "TMZ next = null Node prev name = "Slim next = prev null The diagram is a doubly linked list that holds instances of the Node class. first and last are instance fields in a LL class. Write the code to do the following operations

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

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago

Question

Find the derivative. f(x) 8 3 4 mix X O 4 x32 4 x32 3 -4x - x2

Answered: 1 week ago

Question

Question Can employees make contributions to a profit sharing plan?

Answered: 1 week ago