天空是蓝色的

做好软件为中国 #gcc -c helloworld.c -o helloworld.o //编译目标文件 #gcc helloworld.o -o helloworld //编译成可执行exe #helloworld //运行exe
数据加载中……
[转载]快速排序
快速排序 
 
class Test {
 
 public static void quickSort( int
[] intArr, int startIndex, int endIndex ) {
  int left 
= startIndex;
  int right = endIndex;
  int pivot = (left+right)/2;
  int tmp = 0;
  
  do {
   while( intArr
[left]<intArr[pivot] )  left++;
   while( intArr[right] > intArr[pivot] ) right--;
   
   if( left<
=right ) {
    tmp 
= intArr[left];
    intArr[left] = intArr[right];
    intArr[right] = tmp;
    left++;
    right--;
   }
  }while(left<
=right);
  
  if( left<endIndex ) quickSort( intArr
, left, endIndex );
  if( right>startIndex ) quickSort( intArr, startIndex, right);
 }
      
 public static void main( String
[] argus ) {
  int
[] test = new int[]{5,4,3,2,1};
  quickSort( test, 0 , test.length-1 );
  for ( int i=0; i<test.length; i++ )  System.out.print( "test["+i+"]="+test[i]+"    " );
 }

http://spaces.msn.com/members/zhangqingqi/

posted on 2005-12-31 10:30 bluesky 阅读(426) 评论(0)  编辑  收藏 所属分类: 记事本


只有注册用户登录后才能发表评论。


网站导航: