Login
Immutable PageDiscussionInfoAttachments
Diff for "rei05/C言語"

MMA
Differences between revisions 29 and 30
Revision 29 as of 2012-06-01 16:54:19
Size: 1449
Editor: rei05
Comment:
Revision 30 as of 2012-06-08 17:12:40
Size: 1464
Editor: rei05
Comment:
Deletions are marked like this. Additions are marked like this.
Line 17: Line 17:
 * [[/10031]]

C言語

AOJ解答

Help Me!

未解決

   1 #include  <stdio.h>
   2 
   3 void Sort(int num[],int left,int right); 
   4 
   5 int main()
   6 {
   7         int n,i;
   8         scanf("%d",&n);
   9         int num[n];
  10 
  11         for(i=0;i<n;i++)
  12                 scanf("%d",&num[i]);
  13 
  14         Sort(num,0,n-1);
  15 
  16         for(i=0;i<n;i++)
  17                 printf("%d ",num[i]);
  18         printf("\n");
  19 
  20         return(0);
  21 }
  22 
  23 void Sort(int num[],int left,int right)
  24 {
  25         int i,j,temp;
  26         int center=(left+right)/2;
  27 
  28         while(1){
  29                 i=left;
  30                 j=right;
  31 
  32                 while(num[i]<num[center])
  33                         i++;
  34                 while(num[center]<num[j])
  35                         j--;
  36                 if(i==j)
  37                         break;
  38                 if(num[i]==num[j]){
  39                         i++;
  40                         if(i==j)
  41                                 break;
  42                 }
  43 
  44                 temp=num[i];
  45                 num[i]=num[j];
  46                 num[j]=temp;
  47         }
  48 
  49         if(center-left>=2)
  50                 Sort(num,left,center-1);
  51         if(right-center>=2)
  52                 Sort(num,center+1,right);
  53 }

rei05/C言語 (last edited 2012-07-16 17:50:37 by nomeaning)