i am trying hard to make my mergesort algorithm but at the moment, syntaxically it is correct, but while executing it stops at the split function. please chek this program, its the third one, am trying to simplify mergesort. if you can run the program please tell me what you are doing. am using Borland C/C++ 5 on windows 7.
Code:
#include<iostream.h>#include<conio.h>
#include<stdlib.h>
char a[1000];
void merge(int b[],int c[])
{
char str;
if(b<c){
str=(char)b;
strcat(a,(const char*)str);
str=(char)c;
strcat(a,(const char*)str);
}
else if(b==c){
str=(char)b;
strcat(a,(const char*)str);
}
else{
str=(char)c;
strcat(a,(const char*)str);
str=(char)b;
strcat(a,(const char*)str);
}
}
void copy(int x[], int s, int e, int y[])
{
int i,j=0;
for(i=s;i<=e;i++){
j++;
y[j]=x[i];
}
}
void split(int a[],int l, int h)
{
int b[100],c[100],mid;
mid=(l+h)/2;
copy(a,l,mid,b);
copy(a,mid+1,h,b);
while(h>1)
{
split(b,0,mid+1);
split(c,0,mid+1);
}
merge(b,c);
}
void main()
{
int n, a[1000];
cout<<"Enter the number of elements";
cin>>n;
for(int i=0;i<n;i++)
a[i]=(rand()%1000);
if(n>1)
split(a,0,n);
cout<<a;
}
i can post my previous program also if required.
it is popping up in the assembly language area and i am not understanding wer the error is happening.