- UID
 - 2198
 
 注册时间2005-6-29
阅读权限255
最后登录1970-1-1
副坛主 
    
 
 
 
该用户从未签到  
 | 
 
. 
 
简单实现了一下 支持浮点型、字符型数组排序 
 
/*-------------------------------------------*/ 
 
 
#include <stdio.h> 
#define length 10 
typedef int ElementType; 
 
void Show(ElementType * a,ElementType n) 
{ 
    int i; 
    for(i=0;i<n;i++) 
    printf("%d ",*(a+i)); 
    printf("\r\n"); 
} 
 
void Change(ElementType * a,ElementType * b) 
{ 
    ElementType t; 
    t=*a; 
    *a=*b; 
    *b=t; 
} 
 
void Big(ElementType * a, ElementType * b) 
{ 
    if(*a>*b) 
        Change(a,b); 
} 
 
void Small(ElementType * a, ElementType *b) 
{ 
    if(*a<*b) 
        Change(a,b); 
} 
 
void PaiXu(ElementType * a,int n,char c) 
{ 
    if(n==1)return; 
    switch(c) 
    { 
        case 'b':  
            Big(a,a+1); 
            break; 
        case 's':  
            Small(a,a+1); 
            break; 
        default:  
            return; 
    } 
    PaiXu(a+1,n-1,c); 
    PaiXu(a,n-1,c); 
} 
 
int main() 
{ 
    ElementType a[]={9,1,2,3,4,5,6,7,0,8}; 
    Show(a,length); 
    PaiXu(a,length,'b'); 
    Show(a,length); 
    PaiXu(a,length,'s'); 
    Show(a,length); 
    return 0; 
} |   
 
 
 
 |