Programming Assignment: Basics of Pointers
Purpose: Instead of using vectors, we want to have a parallel implementation of the merge-sort algorithm by using pointers, recursion, and dynamic memory allocation. It is intended to give you exposure to the use of pointers and dynamic memory allocation.
Step 1: Implement the mergeTwoSortedSeries function.
Given a series of sizeOfA sorted values starting at the memory location pointed to by ptrA and a series of sizeOfB sorted values starting at the memory location pointed to by ptrB, implement the following function that can merge the values in these two separate sorted series into a single sorted series of values starting at the memory location pointed to by ptrC.
Step 2: Test the implementation of the mergeTwoSortedSeries function.
Create a loop in your main function to repeatedly do the following test on the mergeTwoSortedSeries function until the user enters a negative value for n1 or n2 in the input:
Ask the user to enter two non-negative integers n1 and n2. Dynamically allocate three separate chunks of memory storages that can hold n1, n2, and (n1+n2) double values respectively. Then use a loop to ask the user to enter a series of n1 sorted values and store them in the chunk that can hold n1 values. Similarly use a loop to ask the user to enter a series of n2 sorted values and store them in the chunk that can hold n2 values. Then call the mergeTwoSortedSeries function appropriately to merge the two series of values into the one sorted series of values stored in the chunk that can hold (n1+n2) values. Output the contents of this final sorted series to verify the result. Then appropriately call delete[ ] to free these two chucks of dynamically allocated memory
You have to make sure that mergeTwoSortedSeries is working perfectly (by doing extensive testing in Step 2) before you proceed to Step 3 below.
Step 3: Implement the mergeSort function.
Implement the following recursive merge sort function by using the mergeTwoSortedSeries function implemented in Step#1.
Step 4: Test the implementation of the mergeSort function.
Create a loop in your main function to repeatedly do the following test on the mergeSort function until the user enters a negative value for n in the input:
Ask the user to enter one non-negative integer n. Dynamically allocate a chunk of memory storage that can hold n double values. Use a loop to ask the user to enter a series of n values and store them in the chunk of memory you just allocated.
Then call the mergeSort function appropriately to sort the series of numbers into one sorted series.
Then print out the contents of this final sorted series to verify the result.
Then appropriately call delete[ ] to free the chuck of dynamically allocated memory.
Attachment:- Assignment.rar