Question: Consider the implementation of the List class using dynamic arrays as discussed in the class/ slides lecture code. Extend the code for the List class




Consider the implementation of the List class using dynamic arrays as discussed in the class/ slides lecture code. Extend the code for the List class with each of the following functions. Each function should be implemented independent of each other. Analyze the asymptotic time complexity of each of the implementations with 'n' considered as the size of the List. (o) Add a member function called printo ) to the List class that prints the contents of the List from index 0 to endOfArray with a space between each element void print ) (ii) Add a member function called subL.ist(int fromIndex, int toIndex) to the List class that returns an object of class List itself. The returned List object is a sub list of the List object on which the subList function is called. The subList should basically create a new List object, copy the contents of the List fromlndex to tolndex) on which the function is called to the new List and return the sub list to the main function. You should not create any other function and just make use of one or more of the existing functions in the current version of the List class List subList(int fromlndex, int tolndex (iii) Add a member function called rotateList(int rotationSpace) to the List class that rotates the elements in the List by rotationSpace' number of elements to the left. For example, rf the contents of the List are (before rotation): 10 12 5 7 19 21, then if the List is rotated to the left with a rotationSpace of 2, then the rotated List should be: 5 7 19 21 10 12. Note that the original List should be updated with the rotated contents so that after calling the rotateList function on the original List object, if one were to print the contents of the original List object, the rotated contents should be printed void rotateList int rotationSpace)l (iv) Add a member function called reverseList() to the List class that reverses the contents of the list. For example if the contents of the List are (before reverse: 10 12 5 7 19 21, then after calling the reverselist function, the contents of the List should be updated as: 21 197 5 12 10. You should implement the reverseL ist function without using any additional memory or temporary array that is proportional to the size of the list. Just one temporary variable (or in other words, a constant amount of additional memory that is independent of the size of the list, denoted O(1) memory) should be sufficient void reverseList l
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
