# Metacode to JAVA

• 11-07-2010, 04:58 PM
woser
Metacode to JAVA
Hi I have a meta code
http://nasza-pralnia.pl/quicksortsplit.bmp
http://nasza-pralnia.pl/split.bmp
I try to convert it for the JAVA, and it wouldn't work, can anybody help me ?

Code:

public static void QuickSortSplit(float E[])
{
int m=0; int n=E.length;

m=split(E);
if(m>1)
{
//QuickSortSplit(E[0..m-1]);
float[] temp=new float[m];
System.arraycopy(E, 0, temp, 0, m);

QuickSortSplit(temp);
System.arraycopy(temp,0,E,0,m);
}
if((n-m-1)>1)
{

//QuickSortSplit(E[m+1..n-1]);
float[] temp=new float[n-m];
for(int i=0; i<n-m; i++)
temp[i]=E[m+i];

QuickSortSplit(temp);
for(int i=0; i<n-m; i++)
E[m+1+i]=temp[i];
QuickSortSplit(E);
}
}
public static int split(float E[])
{
int l=1;
int r=E.length-1;
float tmp;
while(l<=r)
{
while((l<=r) && (E[r]>E[0])) r=r-1;
while((l<=r) && (E[l]<E[0])) l=l+1;
if(l<r)
{
tmp = E[l];
E[l] = E[r];
E[r] = tmp;
l=l+1;
r=r-1;
}
}
if(r>0) {
tmp = E[0];
E[0] = E[r];
E[r] = tmp;
}
return r;
}

• 11-07-2010, 05:13 PM
coltragon
Please tell us which errors you get?
• 11-07-2010, 05:22 PM
woser
When I try 3 elements array with: 1,2,3 the loop never end, but it works for the array 3,2,1

This is a complete code, you can try to compile this for any example array