i need help C++ Quick sort and Insertion sort

#include <ctime>
#include <utility>
#include <stdlib.h>
#include <iostream>
#include <stack>
using namespace std;

/* The following three functions fill the array "a" of size "n"
with the numbers 1 to n in increasing, decreasing, and random order respectively
Only the implementation of the third one has been provided*/
void increasing_order(int* a, int n);
void decreasing_order(int* a, int n);
void random_order(int* a, int n);

/* The following function sorts the array "a" of size "n" using the quicksort algorithm.
It returns an integer value which corresponds to the numbers of comparisons performed to do the sorting */
long quicksort(int* a, int n);

/* The following two functions are used by the quicksort function */
int partition(int*, int, int, long&);
void swap(int &, int &);

/* Other sorting algorithms. The implementation of these functions has not been provided */
long mergesort(int*a,int start, int end){
if (start==end);
return 0;
mergesort (a,start,start(end-start)/2);
mergesort (a,middle+1,end);
mergesort(a,start,middle,end);
}

long insertionsort (int* a, int n){
long counter=0;
int nextElement, j;
for (int i=1; i<n; i++){
nextElement=a[i];
j=i;
counter++;
while (j>0 && nextElement < a[j-1]){
a[j] = a[j-1];
j--;
counter++;
}
a[j] = nextElement;
}
return counter;
}



int main()
{
int n=10; //Tests will be done with array of size 100

int *myarray;
myarray=new int[n]; //Create array of size "n"

random_order(myarray, n); //FILL THE ARRAY WITH NUMBERS IN RANDOM ORDER
//increasing_order or decreasing_order could be used instead

//NOTE: If the size of the array (n) is greater than 100, I suggest you comment this for loop
//Otherwise, it will take very long to print all the numbers to screen
cout<<"*********ORIGINAL ARRAY*********"<<endl<<endl;
for (int i = 0; i < n; i++)
{
cout << myarray[i] << " ";
}

//CALL TO THE QUICKSORT ALGORITHM
long comparisons = quicksort(myarray, n);

//NOTE: If the size of the array (n) is greater than 100, I suggest you comment this for loop
//Otherwise, it will take very long to print all the numbers to screen
cout<<endl<<endl<<"*********SORTED ARRAY*********"<<endl<<endl;
for (int i = 0; i < n; i++)
{
cout << myarray[i] << " ";
}

cout<<endl<<endl<<"Number of comparisons performed: "<<comparisons <<endl<<endl;
system("pause");
}


//Fills the array a of size n with the numbers 1 to n in random order
void random_order(int* a, int n){
cout<<"\nFilling the array ...\n";
srand((unsigned)time(0));
for (int i = 0; i<n; i++){
int randomPosition = (rand() % n);
while (a[randomPosition] >0){
if (randomPosition==0)
randomPosition=n-1;
else randomPosition--;
}
a[randomPosition] = i+1;
}
cout<<"\nDone filling the array ...\n\n";
}

void increasing_order(int*a, int n){
for(int i=0; i<n; i++){
a[i]= i+1;}
}


void decreasing_order(int*a, int n){
for(int i=0; i<n; i--){
a[i] = n-i;}
}

for (i=1, i>n-1 ; i++; )
NextElement=a[i];
i=1;
while(i>o && nextElement < x[n-1])
{
a[i]=a[i=1];
i--;
}

long mergesort(int*a, int n);
{
mergesort(a,0,n/2);
mergesort(a, n/2, n);
merge (a,0,n/2,n);
}

/* long mergesort(int*a,int start, int end){
if (start==end);
return 0;
mergesort (a,start,start(end-start)/2);
mergesort (a,middle+1,end);
mergesort(a,start,middle,end);
}

long insertionsort (int* a, int n){
long counter=0;
int nextElement, j;
for (int i=1; i<n; i++){
nextElement=a[i];
j=i;
counter++;
while (j>0 && nextElement < a[j-1]){
a[j] = a[j-1];
j--;
counter++;
}
a[j] = nextElement;
}
return counter;
}*/

void merge(int* a, int lo, int m, int hi, int n)
{

int i, j, k;
int *b;
b=new int[n];


i=0; j=lo;

while (j<=m)
b[i++]=a[j++];
i=0; k=lo;

while (k<j && j<=hi)
if (b[i]<=a[j])
a[k++]=b[i++];
else
a[k++]=a[j++];
for(int q=0; q<=j; q++)

while (k<j)
a[k++]=b[i++];

}



// Quicksort function:
// sorts array a of size n
// returns the number of comparisons performed
long quicksort(int *a, int n){
long ncomparisons=0;
int left = 0;
int right = n-1;
pair <int,int> p(left,right);
stack<pair<int,int>> mystack;
mystack.push(p);
while (!mystack.empty()){
left = mystack.top().first;
right = mystack.top().second;
mystack.pop();
if (left < right) {
int pivot= partition(a, left, right, ncomparisons);
mystack.push(make_pair(left, pivot-1));
mystack.push(make_pair(pivot+1, right));
}
}
return ncomparisons;
}

int partition(int *a, int left, int right, long& counter)
{
int pivot = ((right-left+1)/2)+left;
int pivotValue = a[pivot];
swap(a[pivot],a[right]);
int storeIndex = left;

for (int i = left; i < right; i++)
{
counter++;
if (a[i] <= pivotValue)
{
swap(a[i], a[storeIndex]);
storeIndex++;
}
}
swap(a[storeIndex], a[right]);
return storeIndex;
}

void swap(int &num1, int &num2)
{
int temp = num1;
num1 = num2;
num2 = temp;


}



IM NOT SURE IF MY QUICK SORT OR INSERTION SORT IS RIGHT...
IM NOT SURE IF MY QUICK SORT OR INSERTION SORT IS RIGHT...


What have you done to test them?
Topic archived. No new replies allowed.