Question: exercise 2 only please Exercise 1 - (4 Marks) Singly LinkedList What is the output of the following Java code? Draw the nodes and their

exercise 2 only please  exercise 2 only please Exercise 1 - (4 Marks) Singly LinkedList
What is the output of the following Java code? Draw the nodes

Exercise 1 - (4 Marks) Singly LinkedList What is the output of the following Java code? Draw the nodes and their links for each line of code to show the memory processes. Consider the definition of the singly linked list Node class that we implemented during the lectures. Assume the node's data fields are info and link, and the info is of type int. list and ptr are reference variables of type Node. Exercise 2 - (10 Marks) Singly LinkedList - Use Netbeans a) Add the following methods to MyLinkedList class that we implemented during the lectures: 1. Write a method isEmpty () that returns true if the list is empty and false otherwise 2. Write a method front () that returns the info value of the first node in the list 3. Write a method back () that returns the info value of the last node in the list 4. Write a method insertAtEnd () that inserts a new node at the end of the list 5. Write a method removeAtEnd () that removes the last node of the list 6. Write a method buildListBackward () that builds a list in backward manner, a new node is always inserted at the beginning of the linked list. Your method should prompt the user for the size of the linked list (number of nodes in the list), then generate random integer values between 1 to 50 and insert them to the list in backward manner. 7. Write a method buildL istForward () that builds a list in forward manner, a new node is always inserted at the end of the linked list. Your method should prompt the user to enter a set of integer numbers then insert them to the list in forward manner. The reading stops when the user enters -999 8. Write a method deletesmailest () that finds and deletes the node with the smallest info in the list. The method should delete the first occurrence and node traversal should be performed only once. 1/2 b) Test the methods above in a tester program as follows: 1. Build a linked list L1 of 10 nodes in backward manner 2. Print L1 3. Print the info of the first node in L1. Use proper output message. 4. Remove two nodes at the end of L1. Hint: call removeAtEnd () two times. 5. Print the info of the last node in L1. Use proper output message. 6. Check if L1 is empty. Use proper output message. 7. Build another linked list L2 of 5 nodes in forward manner 8. Print L2 9. Delete the node with the smallest info in L2 10. Print L2 after deleting the smallest info Exercise 3 - (3 Marks) Recursion Consider the following recursive method: public static int mystery(int z, int n){ if (n==z) return z; else if (n>z) return mystery (z,nz); else return mystery (zn,n); Answer the followign questions: 1. Identify the base case. 2. Identify the general case(s) 3. What is the output of the following statement? Show the recursive calls mystery (8,20); Exercise 4 - (3 Marks) Recursion Write a Java program that contains a recursive method that finds and returns the sum of the elements of an int array. Test the method in the main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!