functie.java

class functie {
public native void sortc( int []vect);
static {
System.loadLibrary("functie");
}
}

functie_imp.c

 #include 
 	 #include "functie.h" 
JNIEXPORT void JNICALL 
 	 Java_functie_sortc(JNIEnv *env, jobject obj, jintArray x) {
 	 int i,j;
 	 jsize l=(*env)->GetArrayLength(env,x);
 	 jint *a=(*env)->GetIntArrayElements(env,x,0);
 	 for ( i = l; --i>=0; )
 	 for ( j = 0; j a[j+1]) {
 	 int T = a[j];
 	 a[j] = a[j+1];
 	 a[j+1] = T;
 	 }
 	 }
 	 (*env)->ReleaseIntArrayElements(env,x,a,0);
 	 } 	

SortItem.java

 import java.io.InputStream;
 	 import java.util.Hashtable;
 	 import java.net.*;
 	 import java.util.Date;
 	 public class SortItem {
 	 static int[] arr;
 	 static boolean prnt=true;
 	 static int len=500;
 	 public static void sort(int[] a) {
 	 int i,j;
 	 for ( i = a.length; --i>=0; )
 	 for ( j = 0; j a[j+1]) {
 	 int T = a[j];
 	 a[j] = a[j+1];
 	 a[j+1] = T;
 	 }
 	 }
 	 }
 	 public static void scramble() {
 	 int[] a = new int[len];
 	 double f = len / (double) a.length;
 	 for (int i = a.length; --i >= 0;) {
 	 a[i] = (int)(i * f);
 	 }
 	 for (int i = a.length; --i >= 0;) {
 	 int j = (int)(i * Math.random());
 	 int t = a[i];
 	 a[i] = a[j];
 	 a[j] = t;
 	 }
 	 arr = a;
 	 }
 	 public static void printArray(){
 	 if (prnt) for(int i=0; i1) len=Integer.parseInt(args[1]);
 	 scramble();
 	 int []z=new int[arr.length];
 	 for (int i=0;i
	
Java la vitez� maxim�

BYTE Rom�nia - decembrie 1997


(C) Copyright Computer Press Agora