However, the number of integers must be a power of 2. In main.c, key[ ] has 16 integers. But as you should already know, the program will not sort if one integers is removed or added. What you are going to do is modify the mergesort.c module so that a non-power of 2 number of integers can be sorted. When you modify a module, indicate by way of comment, what was changed, the date the change was made. You will also need to add or remove an integer to/from key[] in module sort158a.c. You are NOT allowed to change merge.c, mergesort.h or wrt.c files The mergesort function in file mergesort.c MUST call the merge function which it currently does. The main function in sort158a.c you can only change the number of integers in the key[] array Below are 3 examples of output. The first with an array of 15 integers. The second with an array of 16 (power of 2) integers and the third with 17 integers. Example of Output with 15 integers Before mergesort: 4 3 1 67 55 4 -5 37 7 4 2 9 1 -1 6 After mergesort: -5 -1 1 1 2 3 4 4 4 6 7 9 37 55 67 Example of Output with 16 integers Before mergesort: 4 3 1 67 55 8 0 4 -5 37 7 4 2 9 1 -1 After mergesort: -5 -1 0 1 1 2 3 4 4 4 7 8 9 37 55 67 Example of Output with 17 integers Before mergesort: 4 3 1 67 55 8 0 4 -5 37 7 4 2 9 1 -1 6 After mergesort: -5 -1 0 1 1 2 3 4 4 4 6 7 8 9 37 55 67
However, the number of
integers must be a power of 2. In main.c, key[ ] has 16 integers. But as you should already
know, the program will not sort if one integers is removed or added.
What you are going to do is modify the mergesort.c module so that a non-power of 2
number of integers can be sorted. When you modify a module, indicate by way of
comment, what was changed, the date the change was made. You will also need to add or
remove an integer to/from key[] in module sort158a.c.
You are NOT allowed to change merge.c, mergesort.h or wrt.c files
The mergesort function in file mergesort.c MUST call the merge function which it currently does.
The main function in sort158a.c you can only change the number of integers in the key[] array
Below are 3 examples of output. The first with an array of 15 integers. The second with an array
of 16 (power of 2) integers and the third with 17 integers.
Example of Output with 15 integers
Before mergesort:
4 3 1 67 55 4 -5 37 7 4 2 9 1 -1 6
After mergesort:
-5 -1 1 1 2 3 4 4 4 6 7 9 37 55 67
Example of Output with 16 integers
Before mergesort:
4 3 1 67 55 8 0 4 -5 37 7 4 2 9 1 -1
After mergesort:
-5 -1 0 1 1 2 3 4 4 4 7 8 9 37 55 67
Example of Output with 17 integers
Before mergesort:
4 3 1 67 55 8 0 4 -5 37 7 4 2 9 1 -1 6
After mergesort:
-5 -1 0 1 1 2 3 4 4 4 6 7 8 9 37 55 67
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 6 images