Ok I was able to recursively split the index of the array here is the code:
Code:
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
void fillA(Int32[], int);
void printA(Int32[]);
int split(Int32 []);
int _tmain()
{
Console::Write(S"Input N:");
int n= Int32::Parse(Console::ReadLine());
Int32 x[]= new Int32[n];
fillA(x,100);
printA(x);
mergeSort(x)
return 0;
}
void fillA(Int32 d[], int v){
Random *r= new Random();
for(int i=0; i != d->Length; i++)
d[i]=r->Next(1,v);
}
void printA(Int32 d[]){
for(int i=0; i != d->Length; i++)
Console::Write(S"{0} \t",d[i].ToString());
Console::WriteLine();
}
void mergeSort(Int 32 a[]){
split(a, 0, a->Length -1);
}
void split(Int32 a[],low, high) {
if(high > low){
int mid = (high + low)/2;
split(a,low,mid);
split(a,mid+1,high);
combine(a,low, mid+1,high)
}
}
The split function will split indexes until you have a single index remaining. That is, an array of 3 elements will be broken down to o,1,2. Now I dont know how to compare the values at the indexes and sort them. Am i supposed to be doing this while i am splitting? Please any hints and suggestions are most welcome.