javaËæ»úÅÅÁÐÊý×é
ÓÐʱÎÒÃÇÐèÒªËæ»úµÄÅÅÁÐÊý×éÖеÄÔªËØ£¬Ëæ»úÅÅÁÐÊý×飬Ŀǰ³£ÓõÄÓÐÁ½ÖÖ·½·¨£¬µÚÒ»ÖÖ¾ÍÊÇÔªËØA[i]¶ÔÓ¦Ò»¸öÓÅÏȼ¶P[i],¸ù¾ÝÓÅÏȼ¶×÷Ϊ¼üÖµÀ´´ÓÐÂÅÅÐòÊý×é;µÚ¶þÖÖ·½·¨¾ÍÊÇA[i]Ëæ»úµÄ¸úA[i]µ½A[n]ÖеÄÈÎÒâ¸öÔªËؽøÐн»»»,nΪÊý×éµÄ³¤¶È,ÏÂÃæÊÇÓÃjavaʵÏÖÒ»¸ö¼òµ¥ÊµÏÖ.
import java.util.Date;
import java.util.Random;
/*
* Ëæ¼´ÅÅÁÐÊý×飬¸ø¶¨Ò»¸öÊý×飬Ëæ¼´ÅÅÁÐÆäÖеÄÔªËØ£¬Ä¿Ç°Ö÷ÒªÓÐÁ½ÖÖ·½·¨
*/
public class RandomSort {
public static void main(String args[]){
int data[]=new int[]{1,42,51,62,8,94,23,13,40,5};
//int p[]=getRandom(1,-8,100);
//show(p);
show(data);
permuteBySort(data);
show(data);
randomizeInPlace(data);
show(data);
}
/*
* Ëæ»úÅÅÁÐÊý×é,ʹÓÃÓÅÏȼ¶·½Ê½,ÿ¸öÊý×éÔªËØA[i] ¶ÔÓ¦Ò»¸öÓÅÏȼ¶P[i]£¬
* È»ºóÒÀ¾ÝÓÅÏȼ¶¶ÔÊý×é½øÐÐÅÅÐò
*/
private static void permuteBySort(int[] data)
{
int len=data.length;
int len3=len*len*len;
int P[]=getRandom(1,len3,len);
//ðÅÝÅÅÐò
for(int i=len-1; i>0; i--)
{
for(int j=0; j<i ; j++)
{
if(P[j]>P[j+1])
{
int temp=data[j];
data[j]=data[j+1];
data[j+1]=temp;
temp=P[j];
P[j]=P[j+1];
P[j+1]=temp;
}
}
}
}
/*
* ÔªËØA[i]ÊÇ´Ó ÔªËØA[i]µ½A[n]ÖÐËæ»úÑ¡È¡µÄ
*/
private static void randomizeInPlace(int[] data)
{
Date dt=new Date();
Random random=new Random(dt.getSeconds());
int len=data.length;
for(int i=0; i<len; i++)
{
int pos=(int)(random.nextDouble()*(len-i+1)+i)-1;
int temp=data[i];
data[i]=data[pos];
data[pos]=temp;
}
}
/*
* »ñµÃÔÚaµ½bÖ®¼äµÄn¸öËæ»úÊý
*/
private static int[] getRandom(int a,int b,int n)
{
if(a>b)
{
int temp=a;
a=b;
b=temp;
}
Date dt=new Date();
Random random=new Random(dt.getSeconds());
int res[]=new int[n];
for(int i=0; i<n; i++)
{
res[i]=(int)(random.nextDouble()*(Math.abs(b-a)+1))+a;
}
return res;
}
private static void show(int[] data)
{
System.out.print
Ïà¹ØÎĵµ£º
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ
......
ÏÂÃæʹÓÃÒ»¸öjavaʵÏֵĵü´ú°æµÄµÝ¹é°æµÄ²åÈëÅÅÐò¡£
package sort;
import java.util.Date;
import java.util.Random;
/*
* ²åÈëÅÅÐò
*/
public class InsertSort{
public static void main(String args[])
{
int len = 20;
Date date = new Date();
Random random = new Random(date.getSeconds()); ......
ÏÂÃæÊÇʹÓÃjavaʵÏֵĵݹéÄæÐò¶Ô²éÕÒ£¬ËùνµÄÄæÐò¶Ô¾ÍÊÇÔÚÊý×éA[]ÖÐÈç¹û i < j ,²¢ÇÒA[i] > A[j], ÔòÎÒÃÇ˵A[i]ºÍA[j]ÊÇÒ»¶ÔÄæÐò¶Ô¡£Èç¹ûÓÃÆÕͨµÄË㷨ʵÏֵĻ°£¬²éÕÒµÄʱ¼ä¸´ÔӶȣ¬ÊÇO(N*N)£¬Ê¹ÓÃÕâÀïµÄ¶Ó¹æµÄ·½Ê½²éÕҵĻ°£¬Ê±¼ä¸´ÔÓ¶ÈÊÇO(N*lgN)
import java.util.Date;
import java.util.Random;
/*
* ʹÓõݹ ......
»ôÄɹæÔò¶àÏîʽ¼ÆËãÈç¹ûʹÓÃÆÓËصĶàÏîʽÇóÖµ£¬Ê±¼ä¸´ÔÓ¶ÈΪO(n*n)£¬¶øÊÇÓÃÁË»ôÄɹæÔò¿ÉÒÔʹÓõݹé»òÕßµü´úÀ´ÊµÏÖ£¬Ê±¼ä¸´ÔÓ¶ÈÊÇO(n),ÏÂÃæÊÇÔ´´úÂë:
/*
* ʵÏÖ»ôÄɹæÔòµÄ¶àÏîʽ¼ÆËãʱ¼ä¸´ÔÓ¶ÈΪO(N)
*/
public class HuonaRule {
public static void main(String args[])
{
double data[]=new double[]{1.0,2, ......
Ò»£º×¼±¸ www.savarese.org download
1. rocksaw-1.0.0-src.tar.gz
2. vserv-tcpip-0.9.2-src.tar.gz
¶þ£º±àÒëÔ´ÎļþµÃµ½jar°ü ʹÓÃAnt
1. build vserv-tcpip-0.9.2-src
ÔÚvserv-tcpip-0.9.2Ŀ¼ÏÂÃ潨һ¸ötestsĿ¼£¬È»ºóÔÚcmd´°¿ÚϽøÈë ......