ashariat
چهارشنبه 04 اسفند 1389, 07:04 صبح
سلام
این برنامه MergeSort که نوشتم مشکل داره، کسی میتونه کمکم کنه؟
public class Main {
public static void main(String[] args) {
int a[]={-1,5,4,10,1,2,15,4};
Main pgm=new Main();
pgm.MergeSort2(a,0,8);
}
void MergeSort2(int a[],int left,int right)
{
if(left<right)
{
int center=(left+right)/2;
MergeSort2(a,left,center);
MergeSort2(a,center+1,right);
Merge2(a,left,right);
for(int i=0;i<8;i++)
System.out.println(a[i]);
System.out.println("\n");
}
}
void Merge2(int a[],int low,int high)
{
int mid=(low+high)/2;
int temp[]=new int[high];
for(int i=low;i<high;i++)
temp[i]=a[i];
int j=low;
int k=mid;
for(int i=low;i<high;i++)
if(temp[j]<temp[k] && j<mid){
a[i]=temp[j];
j++;
}
else if(k<high){
a[i]=temp[k];
k++;
}
}
}
این برنامه MergeSort که نوشتم مشکل داره، کسی میتونه کمکم کنه؟
public class Main {
public static void main(String[] args) {
int a[]={-1,5,4,10,1,2,15,4};
Main pgm=new Main();
pgm.MergeSort2(a,0,8);
}
void MergeSort2(int a[],int left,int right)
{
if(left<right)
{
int center=(left+right)/2;
MergeSort2(a,left,center);
MergeSort2(a,center+1,right);
Merge2(a,left,right);
for(int i=0;i<8;i++)
System.out.println(a[i]);
System.out.println("\n");
}
}
void Merge2(int a[],int low,int high)
{
int mid=(low+high)/2;
int temp[]=new int[high];
for(int i=low;i<high;i++)
temp[i]=a[i];
int j=low;
int k=mid;
for(int i=low;i<high;i++)
if(temp[j]<temp[k] && j<mid){
a[i]=temp[j];
j++;
}
else if(k<high){
a[i]=temp[k];
k++;
}
}
}