Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Question 1 A non-circular, singly linked list Abstract Data Type has a private Node pointer, called first , which points to the rst 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 be read or written to by using the eld names n.val and n.next for the value and next elds 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 nfrom the list and throws an IllegalArgumentException if no such element exists or if nis less than 0. The rst node is numbered 0. Fill in the missing part of the pseudocode for this function below: 1 v o i d d e l e t e n t h ( i n t n ) 2 f 3 / / WRITE THE CODE THAT SHOULD BE HERE 4 r e t u r n 5 g (b) Assume that this ADT has two di erent di erent methods to delete all the elements from the singly linked list as follows: 1 v o i d d e l e t e a l l f r o m s t a r t ( ) 2 f 3 w h i l e ( s i z e >0 ) 4 d e l e t e n t h ( 0 ) 5 r e t u r n 6 g 7 8 v o i d d e l e t e a l l f r o m e n d ( ) 9 f 10 w h i l e ( s i z e >0 ) 11 d e l e t e n t h ( s i z e 1 ) 12 r e t u r n 13 g 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 ecient method to delete all elements from the list.

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