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

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

ID: 3586747 • Letter: T

Question

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 from the front of the list. In the method provided remove “Slimy” assume next and prev are public variables that you don’t 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, don’t 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 don’t 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 don’t 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 don’t 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

Explanation / Answer

A,

public void delete()

{

Node *temp = NULL;

temp = first;

if (temp) {

first = temp -> next;

first -> prev = NULL;

delete (temp);

temp = NULL;

}

}

B.

public void insert()

{

Node ref = new Node(“TEA”);

Node *temp = first;

while (temp) {

if (!strcmp(temp->name, "Dirty") {

ref -> next = temp -> next;

temp -> next -> prev = ref;

temp -> next = ref;

ref -> prev = temp;

return;

}

}

}

C.

public void deleteEnd()

{

node *temp = last;

if (temp) {

last = temp -> prev;

last -> next = NULL;

delete(temp);

temp = NULL;

}

}

D.

public void insert()

{

Node ref = new Node(“Donkey”);

Node *temp = last;

if (temp) {

ref -> next = NULL;

temp -> next = ref;

ref -> prev = temp;

}

}

E.

Previously, before A->D

<<Slimy>> ---> <<Dirty>> ---> <<Rumor>> ---> <<TMZ>> --->NULL
NULL <---- <--- <--- <---

After A->D::

<<Dirty>> ---> <<TEA>> ---> <<Rumor>> ---> <<Donkey>> --->NULL
NULL <---- <--- <--- <---


Recursion outputs::

A.mystery1(4);

4
3
2
1
1
2
1
1
3
2
1
1
2
1
1


It will print till it becomes the n =1 then return and print last value
which was 2 and it will print 1 and return to the last value which was 3 and
print 2 and 1 and so on.

B.mystery2(4);


1
2
1
3
1
2
1
4
1
2
1
3
1
2
1


C.mystery3(4)

1
1
2
1
1
2
3
1
1
2
1
1
2
3
4


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote