Requirement
Using C++ Class and pointers, implement Single-Linked List of integers. You are not allowed to use STL. Consider the following for your linked list implementation:
- Update the List class implementations in the lecture slides so that the List does not have any duplicate value.
- Also make the necessary updates to the List class to maintain a sorted list (i.e. the Nodes are in increasing order of data values). In particular, replace all the insert methods, and replace them with insert(int x), which inserts x in the right position so that the List remains sorted.
- Implement DeleteMid() to delete the middle element (when the list contains an odd number of elements) or middle two elements (when the list contains an even number of elements).
- Using recursion, implement Ascend() and Descend() to display the entire list in ascending and descending orders, respectively.
Sample Input
1 | 3 // Total no of input sets |
Sample Output (for Input set 1)
1 | Sorted List: 4 5 10 |