Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用递归排啊,0MS绝对,呵!!!

Posted by ssadwlll at 2008-03-23 11:25:17 on Problem 2388
void run(int* pData,int left,int right) 
{ 
     int i,j; 
     int middle,iTemp; 
     i = left; 
     j = right; 
     middle = pData[(left right)/2]; //求中间值 
     do{ 
         while((pData[i]<middle) && (i<right)) //从左扫描大于中值的数 
             i++ ; 
         while((pData[j]>middle) && (j>left)) //从右扫描大于中值的数 
             j--; 
         if(i<=j) //找到了一对值 
         { 
         //交换 
             iTemp = pData[i]; 
             pData[i] = pData[j]; 
             pData[j] = iTemp; 
             i ++; 
             j--; 
          } 
         }while(i<=j); //如果两边扫描的下标交错,就停止(完成一次) 

         //当左边部分有值(left<j),递归左半边 
     if(left<j) 
         run(pData,left,j); 
     //当右边部分有值(right>i),递归右半边 
     if(right>i) 
         run(pData,i,right); 
     }


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator