Chinaunix首页 | 论坛 | 博客
  • 博客访问: 850249
  • 博文数量: 190
  • 博客积分: 7021
  • 博客等级: 少将
  • 技术积分: 1752
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-17 19:26
文章分类

全部博文(190)

文章存档

2014年(9)

2011年(32)

2010年(149)

我的朋友

分类: C/C++

2010-10-14 12:07:18


#include <string.h>
struct A{
       int id;
       char *name;
}

int compare_A(const struct A* a1, const struct A* a2 ){
       if (a1->id > a2-> id)
               return 1;
       else if (a1->id < a2->id)
               return -1;
       else{
               if(strcmp(a1->name. a2->name) >= 0)
                       return 1;
               else
                       return -1;
       }
}

void sort_A(struct A [] input, unsigned int n){
       int i,j;
   int temp;
   for(i=1;i<n;i++)
   {
               temp = input[i];
               for(j=i ; j>0 && compare_A(temp, input[j-1]) < 0 ; j--)
               {
                       input[j]=input[j-1];
               }
       input[j+1]=temp;

}
 


阅读(2339) | 评论(1) | 转发(0) |
0

上一篇:__func__的作用

下一篇:字符串的基本操作

给主人留下些什么吧!~~

chinaunix网友2010-10-14 17:12:21

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com