Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2538814
  • 博文数量: 308
  • 博客积分: 5547
  • 博客等级: 大校
  • 技术积分: 3782
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-24 09:47
个人简介

hello world.

文章分类

全部博文(308)

分类: C/C++

2010-07-19 17:16:06

代码如下:

#include <stdio.h>

void maopao_asc_sort(int[],int);
void print_shuzu(int[],int);
void maopao_desc_sort(int[],int);
int main()
{
    int a[11]={30,5,20,4,50,60,84,58,31,26,33};
    printf("the soure data is :\n");
    print_shuzu(a,11);
    maopao_asc_sort(a,11);
    printf("\nthe sorted numbers:\n");
    print_shuzu(a,11);
    printf("\nthe desc sorted numbers:\n");
    maopao_desc_sort(a,11);
    print_shuzu(a,11);
    system("pause");
    return 1;
}

void maopao_asc_sort(int a[],int n)
{
    int i,j,t;
    for (i=0;i < n - 1;i++)
    {
        for (j=0;j<n - 1 - i;j++)
        {
            if(a[j] > a[j+1])
            {
                    t = a[j];
                    a[j] = a[j+1];
                    a[j+1] = t;
            }
        }
    }
}

void maopao_desc_sort(int a[],int n)
{
    int i,j,t;
    for (i=0;i < n - 1;i++)
    {
        for (j=0;j<n - 1 - i;j++)
        {
            if(a[j] < a[j+1])
            {
                    t = a[j];
                    a[j] = a[j+1];
                    a[j+1] = t;
            }
        }
    }
}

void print_shuzu(int a[],int n)
{
     int i;
     for (i=0;i<n;i++)
     {
         printf("%d ",a[i]);
     }
}


阅读(830) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~