google rss rss

          doneykoo [Ouditian]

          DKzone- Ouditian Technology

          qsort

           1 #include "stdafx.h"
           2 
           3 #include "stdlib.h"
           4 #include "string.h"
           5 #include "stdio.h"
           6 
           7 int cmp_i(const void *a, const void *b)
           8 {
           9     int res = *(int *)a - *(int *)b;
          10     return res;
          11 }
          12 int cmp_s(const void *a, const void *b)
          13 {
          14     int res = strcmp((char *)a, (char *)b);
          15     return res;
          16 }
          17 
          18 int main()
          19 {
          20     int values[] = {3,3546,6134,1,234,12435,51,3,4,32,3241,34514,5};
          21     char strs[][15= {"32","66","6134","1","234","12435","51","3","4","32","3241","34514","5"};
          22 
          23     printf("-------------------\nQsort int\n");
          24     for(int i=0;i<10;i++)
          25     {
          26         printf("%d\t",values[i]);
          27     }
          28     printf("\n");
          29     qsort(values, 10sizeof(int), cmp_i);
          30     for(int i=0;i<10;i++)
          31     {
          32         printf("%d\t",values[i]);
          33     }
          34     printf("\n");
          35     
          36     printf("-------------------\nQsort str\n");
          37     for(int i=0;i<10;i++)
          38     {
          39         printf("%s\t",strs[i]);
          40     }
          41     printf("\n");
          42     qsort(strs, 10sizeof(char)*15, cmp_s);
          43     for(int i=0;i<10;i++)
          44     {
          45         printf("%s\t",strs[i]);
          46     }
          47 
          48 }
          49 

          posted on 2009-02-24 15:58 DoNeY 閱讀(219) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
            doneykoo blogjava
            
          主站蜘蛛池模板: 格尔木市| 博野县| 凤冈县| 屯留县| 古田县| 泽库县| 盱眙县| 禄丰县| 佳木斯市| 南江县| 韩城市| 大同县| 灵石县| 慈利县| 泗水县| 南溪县| 南澳县| 惠州市| 盐边县| 湘乡市| 马龙县| 忻城县| 渝北区| 广德县| 南陵县| 平定县| 石门县| 奉贤区| 武山县| 离岛区| 弋阳县| 岐山县| 多伦县| 荣成市| 仪陇县| 洛川县| 司法| 潞城市| 海盐县| 铜山县| 阳信县|