Let xHead, yHead and zHead be the head pointers of 3 linked lists of integers (called X-list, Y-list and Z-list, respectively, from here). X-list and Y-list are each sorted (in non-decreasing order) in itself and each may be empty. Z-list is initially empty (i.e., zHead initially contains the null pointer). Develop and test a recursive C++ function called SortedMergeRecur that combines the nodes in X-list and Y-list into Z-list such that, after calling the function, Z-list is a sorted list (in non-decreasing order) containing all the nodes initially contained in X-list and Y-list – X-list and Y-list should both be empty after the call. |
|
Other specifications/requirements: |
|
● |
Each node of the list has the following structure: |
|
|
|
struct Node { int data; Node *link; }; |
|
|
► |
Have only three parameters (each a pointer-to-Node) and no return value (be a void function). |
|
|
► |
Not use any global variables or static local variables. |
|
|
► |
Not use any looping constructs (for, while, do-while, ...). |
|
|
► |
Be directly (not indirectly) recursive. |
|
|
► |
Not create any new nodes, destroy any existing nodes or copy/replace the data item of any node. |
|
|
► |
Not make temporary copies of the data involved using any other storage structures (arrays, stacks, queues, etc.). |
|
|
► |
Use (if ever needed) no more than a small number of pointers to hold certain link addresses. |
|
|
|
○ |
Not make temporary copies of the entire list's link addresses wholesale. |
|
● |
Z-list should be sorted at all times as it "grows" from an empty list to one that contains all the nodes originally contained in X-list and Y-list. |
|
|
► |
What this means is that you should not, for instance, attempt to first append all the nodes in X-list to Z-list, then append all the nodes in Y-list to Z-list, and finally use a sorting algorithm of some kind to sort the nodes in Z-list. |
Fill in the prototype for SortedMergeRecur in the supplied header file. |
|
● |
Fill in the definition for SortedMergeRecur in the supplied implementation file. |
Process or set of rules that allow for the solving of specific, well-defined computational problems through a specific series of commands. This topic is fundamental in computer science, especially with regard to artificial intelligence, databases, graphics, networking, operating systems, and security.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images