Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem One: (25 points. 4 points each for first five questions. 5 points for question 6) You textbook listed common functionality that a list should
Problem One: (25 points. 4 points each for first five questions. 5 points for question 6) You textbook listed common functionality that a list should have (refer to Table 2.1.2). However, your book only implemented algorithm for insertAfter and remove. In this problem, you are asking to implement the rest common functionality in table 2.1.2.
- append: which append the given node after the tail of the list
- prepend: which insert the given node to the front of the head of the list
- printList: which print all node data in order as their node in the list
- sort: Sort the list items in ascend order
- isEmpty: Return true if the list is empty; false otherwise
- For printListReversely functionality, if the list is a single linked list, we cannot step through the list reversely. How would you implement this printListReversely algorithm?
Problem Two: (15 points, 5 points each) In problem one, we didnt implement getLength function. This function has some challenge.
- For getLength function, one implement is that we can step through the list, from head to tail, and count. Write algorithm for this implementation
- In previous implementation, what is the run time?
- If I want constant run time for getLength function, what change needs to be made for List data structure? How this change will affect the implementation of other functions such as insertAfter and remove?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started