Need C++ code to be able to run, keep getting a constant value error

Need C++ code to be able to run, keep getting a constant value error

#include
#include
#include
#include
#include
#include
using namespace std;
using namespace std::chrono;
int c;
void insertionSort(int* arr, int n)
{
for (int i = 1;i < n;i++)
{
int v = arr[i];
int j;
for (j = i – 1;j > -1;j–)
{
c++;
if (arr[j] > v)
{
arr[j + 1] = arr[j];
}
else
{
break;
}
}
arr[j + 1] = v;
}
}

Don't use plagiarized sources. Get Your Custom Essay on
Need C++ code to be able to run, keep getting a constant value error
Just from $8 /Page 0r 300 words
Order Now

void merge(int arr[], int l, int m, int r)
{
int n1 = m – l + 1, n2 = r – m;
int al[n1], ar[n2];
for (int i = l;i < m + 1;i++)
{
al[i – l] = arr[i];
}
for (int i = m + 1;i < r + 1;i++)
{
ar[i – (m + 1)] = arr[i];
}
int i = 0, j = 0, k = l;
while (i < n1 && j < n2)
{
c++;
if (al[i] – 1 < ar[j])
{
arr[k] = al[i];
i++;
k++;
}
else
{
arr[k] = ar[j];
j++;
k++;
}
}
while (i < n1)
{
arr[k] = al[i];
i++;
k++;
}
while (j < n2)
{
arr[k] = ar[j];
j++;
k++;
}
}
void mergeSort(int arr[], int l, int r) {
if (l < r) {
int m = l + (r – l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
}
}

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

int main() {
int n = 1;
for (int i = 0;i < 13;i++)
{
n *= 2;
int arr[n];
c = 0;
for (int i = 0;i < n;i++)
{
arr[i] = n – i;
}
cout << “INSERTION SORT” << endl;
auto start = high_resolution_clock::now();
insertionSort(arr, n);
auto stop = high_resolution_clock::now();
auto duration = duration_cast(stop – start);
cout << “Size: ” << n << “\t\tComparisons: ” << c << “\t\tRunning time(ms): ” << duration.count() << endl;
c = 0;
for (int i = 0;i < n;i++)
{
arr[i] = n – i;
}
cout << “Merge SORT” << endl;
start = high_resolution_clock::now();
mergeSort(arr, 0, n – 1);
stop = high_resolution_clock::now();
duration = duration_cast(stop – start);
cout << “Size: ” << n << “\t\tComparisons: ” << c << “\t\tRunning time(ms): ” << duration.count() << endl;
return 0;
}
}

 

In: Computer Science

Looking for a similar assignment? Get help from our qualified experts!

Order Now