Question
C++ Pleaseeee!!!! Please these be implemented in the program below. 1- Create the count for InsertionSort, MergeSort, HeapSort, and Quick sort, and print the InsertionCount,
C++ Pleaseeee!!!!
Please these be implemented in the program below.
1- Create the count for InsertionSort, MergeSort, HeapSort, and Quick sort, and print the InsertionCount, MergeCount, HeapCount and QuickCount for each given file. Something like the table in the image "test case"
Count variable is =0 for all the sorts
2- Instead of printing the output the before and after of each sort for each file. I want the before and after for each sort store in new files called Output8.txt, Output16.txt, etc...
Given files:
Num8.txt = 2 8 3 1 7 6 5 4
Num16.txt = 15 13 8 4 16 9 10 12 7 11 1 14 6 3 2 5
Num32.txt = 1 15 13 7 32 19 11 6 17 24 26 18 4 27 10 31 30 16 25 28 23 3 21 5 8 20 29 22 2 12 14 9
Num64.txt = 23 44 56 15 4 61 21 11 24 42 25 31 18 52 13 58 59 27 60 5 45 26 46 7 43 55 30 19 53 9 12 36 6 50 16 51 28 14 29 3 32 33 2 17 57 49 35 41 47 22 63 54 40 20 62 48 38 10 39 34 8 1 37 64
Num128.txt = 70 46 44 26 35 86 41 119 17 103 102 77 55 105 21 38 118 9 116 98 23 109 94 40 120 75 51 32 106 122 62 58 124 37 93 85 97 27 29 111 57 7 65 6 76 5 30 84 14 91 72 60 88 45 123 110 128 42 87 114 11 49 34 33 66 74 10 53 24 81 50 127 47 8 43 79 117 101 22 3 18 64 61 89 125 63 121 99 1 67 92 59 68 71 80 78 82 28 20 96 113 39 13 107 115 12 15 126 31 83 73 4 69 108 16 54 56 48 104 90 25 36 95 112 19 2 100 51
C++ program
#include
#include
using namespace std;
void display(int A[], int size) {
for (int i = 0; i
cout
cout
}
void Insertion_Sort(int A[], int n) {
int i, key, j;
for (j = 2; j
key = A[j];
i = j - 1;
while (i >= 0 && A[i] > key) {
A[i + 1] = A[i];
i = i - 1;
} A[i + 1] = key;
}
}
void merge(int A[], int p, int q, int r)
{
int i, j, k, n1, n2;
n1 = (q - p) + 1;
n2 = (r - q);
int lA[n1], rA[n2];
for (i = 0; i
lA[i] = A[(p + i) + 1];
for (j = 0; j
rA[j] = A[q + j];
i = 0;
j = 0;
k = p;
while (i
{
if (lA[i]
{
A[k] = lA[i];
i++;
}
else
{
A[k] = rA[j];
j++;
}
k++;
}
while (i
{
A[k] = lA[i];
i++;
k++;
}
while (j
{
A[k] = rA[j];
j++;
k++;
}
}
void Merge_Sort(int A[], int p, int r)
{
int q;
if (p
{
q = (p + r) / 2;
Merge_Sort(A, p, r);
Merge_Sort(A, q + 1, r);
merge(A, p, q, r);
}
}
void Max_Heapify(int A[], int n, int i)
{
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;
if (l A[largest])
{
largest = 1;
}
if (r A[largest])
{
largest = r;
}
if (largest != i)
{
swap(A[i], A[largest]);
Max_Heapify(A, n, largest);
}
}
void Heap_Sort(int A[], int n)
{
for (int i = n / 2 - 1; i >= 0; i--)
Max_Heapify(A, n, i);
for (int i = n - 1; i >= 0; i--)
{
swap(A[0], A[i]);
Max_Heapify(A, i, 0);
}
}
int PARTITION(int A[], int p, int r)
{
int x = A[r];
int i = p - 1;
int temp;
for (int j = p; j
{
if (A[j]
{
i += 1;
temp = A[i];
A[i] = A[j];
A[j] = temp;
}
}
temp = A[i + 1];
A[i + 1] = A[r];
A[r] = temp;
return (i + 1);
}
void QUICKSORT(int A[], int p, int r)
{
if (p
{
int q = PARTITION(A, p, r);
QUICKSORT(A, p, q - 1);
QUICKSORT(A, q + 1, r);
}
}
void readFile(string filename, int arr[]){
fstream fread(filename, ios::in);
string num;
int i = 0;
while (!fread.eof()) {
fread>>num;
arr[i++] = stoi(num);
}
fread.close();
}
int main(){
int arr8[8], arr16[16], arr32[32], arr64[64], arr128[128];
cout
//read file Num8.txt into array arr8
readFile("Num8.txt", arr8);
cout
display(arr8, 8);
//insertion sort
Insertion_Sort(arr8, 8);
cout
display(arr8, 8);
//reinitialize array
readFile("Num8.txt", arr8);
cout
display(arr8, 8);
//Merge_Sort(arr8, 0, 8);
cout
display(arr8, 8);
//reinitialize array
readFile("Num8.txt", arr8);
cout
display(arr8, 8);
Heap_Sort(arr8, 8);
cout
display(arr8, 8);
//reinitialize array
readFile("Num8.txt", arr8);
cout
display(arr8, 8);
QUICKSORT(arr8, 0, 7);
cout
display(arr8, 8);
////////////////Sorting on Num16.txt///////////////
cout
//read file Num16.txt into array arr16
readFile("Num16.txt", arr16);
cout
display(arr16, 16);
//insertion sort
Insertion_Sort(arr16, 16);
cout
display(arr16, 16);
//reinitialize array
readFile("Num16.txt", arr16);
cout
display(arr16, 16);
//Merge_Sort(arr16, 0, 15);
cout
display(arr16, 16);
//reinitialize array
readFile("Num16.txt", arr16);
cout
display(arr16, 16);
//Heap_Sort(arr16, 16);
cout
display(arr16, 16);
//reinitialize array
readFile("Num16.txt", arr16);
cout
display(arr16, 16);
QUICKSORT(arr16, 0, 15);
cout
display(arr16, 16);
////////////////Sorting on Num32.txt///////////////
cout
//read file Num32.txt into array arr32
readFile("Num32.txt", arr32);
cout
display(arr32, 32);
//insertion sort
Insertion_Sort(arr32, 32);
cout
display(arr32, 32);
//reinitialize array
readFile("Num32.txt", arr32);
cout
display(arr32, 32);
//Merge_Sort(arr32, 0, 31);
cout
display(arr32, 32);
//reinitialize array
readFile("Num32.txt", arr32);
cout
display(arr32, 32);
//Heap_Sort(arr32, 32);
cout
display(arr32, 32);
//reinitialize array
readFile("Num32.txt", arr32);
cout
display(arr32, 32);
QUICKSORT(arr32, 0, 31);
cout
display(arr32, 32);
////////////////Sorting on Num64.txt///////////////
cout
//read file Num64.txt into array arr64
readFile("Num64.txt", arr64);
cout
display(arr64, 64);
//insertion sort
Insertion_Sort(arr64, 64);
cout
display(arr64, 64);
//reinitialize array
readFile("Num64.txt", arr64);
cout
display(arr64, 64);
//Merge_Sort(arr64, 0, 64);
cout
display(arr64, 64);
//reinitialize array
readFile("Num64.txt", arr64);
cout
display(arr64, 64);
//Heap_Sort(arr64, 64);
cout
display(arr64, 64);
//reinitialize array
readFile("Num64.txt", arr64);
cout
display(arr64, 64);
QUICKSORT(arr64, 0, 63);
cout
display(arr64, 64);
////////////////Sorting on Num128.txt///////////////
cout
//read file Num128.txt into array arr128
readFile("Num128.txt", arr128);
cout
display(arr128, 128);
//insertion sort
Insertion_Sort(arr128, 128);
cout
display(arr128, 128);
//reinitialize array
readFile("Num128.txt", arr128);
cout
display(arr128, 128);
//Merge_Sort(arr128, 0, 8);
cout
display(arr128, 128);
//reinitialize array
readFile("Num128.txt", arr128);
cout
display(arr128, 128);
//Heap_Sort(arr128, 128);
cout
display(arr128, 128);
//reinitialize array
readFile("Num128.txt", arr128);
cout
display(arr128, 128);
QUICKSORT(arr128, 0, 127);
cout
display(arr128, 128);
}
2. Test case output: include pdf printout of the results of running your program with your test cases. Include the whole sorted file for files Num8.txt, Num 16.txt, Num32.txt and Num 64.txt. For each of other files include pdf of the sorted file consisting of array items with index values of 51 through 100 only. Print the specified output for the 48 files (you can layout the results into fewer pages as long as you make separations clear). Each section should have a header at the top explaining what it is and then the list of array items. 3. Test case summary: The test case summary should be presented in the form of a table. Each entry in the table should be the value of count for one of the sorts after sorting one of the data sets. The table should have the form on the next page Insertion sort Test Case Summary Merge sort Heapsort Quicksort Num8.txt Num 16.txt Num32.txt Num64.txt Num1 28.txtStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started