Question: Question 1 A non-circular, singly linked list Abstract Data Type has a private Node pointer, called first, which points to the first node of the

Question 1 A non-circular, singly linked list Abstract Data Type has a private Node pointer, called first, which points to the first node of the list. This ADT does not maintain a header pointer to the last node of the list, but it does maintain a variable size to keep track of the number of nodes in the list. Given a pointer to a node n, assume that values can read or written to by using the field names n.val and n.next for the value and next fields of the node respectively. Assume that a garbage collector is being used, so nodes do not need to be explicitly freed. Use END for invalid or null address pointer values. (a) delete nth(int n) is a non-recursive method of the ADT that removes node number n from the list and throws an IllegalArgumentException if no such element exists or if n is less than 0. The first node is numbered O. Fill in the missing part of the pseudocode for this function below: void delete_nth (int n) { // WRITE THE CODE THAT SHOULD BE HERE return 3 [10 marks] (b) Assume that this ADT has two different different methods to delete all the elements from the singly linked list as follows: void delete_all_from_start() 2{ while (size > 0) delete-nth (0) return } 10 8 void delete_all_from_end() { while (size > 0) delete-nth (size - 1) 12 return 13} 11 Give the complexities of these two methods in big o notation and explain how you derived them. Write the pseudocode for a much simpler and more efficient method to delete all elements from the list. [10 marks] 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
