CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
【经验总结】不能实施并行处理的情况 浅谈并行编程中的任务分解模式
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  图形处理/算法

寻找int[k]数组的快速排序算法

楼主wangjiandy(没有你,会不会更孤独)2002-03-18 16:58:47 在 VC/MFC / 图形处理/算法 提问

我写不出来,请帮助! 问题点数:20、回复次数:4Top

1 楼ndy_w(carpe diem)回复于 2002-03-18 17:00:28 得分 0

call   qsort();Top

2 楼wangjiandy(没有你,会不会更孤独)回复于 2002-03-18 17:04:06 得分 0

能不能仔细点??Top

3 楼ndy_w(carpe diem)回复于 2002-03-18 17:09:46 得分 20

qsort  
  Performs   a   quick   sort.  
   
  void   qsort(   void   *base,   size_t   num,   size_t   width,   int   (__cdecl   *compare   )(const   void   *elem1,   const   void   *elem2   )   );  
   
  Routine   Required   Header   Compatibility    
  qsort   <stdlib.h>   and   <search.h>   ANSI,   Win   95,   Win   NT    
   
   
  For   additional   compatibility   information,   see   Compatibility   in   the   Introduction.  
   
  Libraries  
   
  LIBC.LIB   Single   thread   static   library,   retail   version    
  LIBCMT.LIB   Multithread   static   library,   retail   version    
  MSVCRT.LIB   Import   library   for   MSVCRT.DLL,   retail   version    
   
   
  Return   Value  
   
  None  
   
  Parameters  
   
  base  
   
  Start   of   target   array  
   
  num  
   
  Array   size   in   elements  
   
  width  
   
  Element   size   in   bytes  
   
  compare  
   
  Comparison   function  
   
  elem1  
   
  Pointer   to   the   key   for   the   search  
   
  elem2  
   
  Pointer   to   the   array   element   to   be   compared   with   the   key  
   
  Remarks  
   
  The   qsort   function   implements   a   quick-sort   algorithm   to   sort   an   array   of   num   elements,   each   of   width   bytes.   The   argument   base   is   a   pointer   to   the   base   of   the   array   to   be   sorted.   qsort   overwrites   this   array   with   the   sorted   elements.   The   argument   compare   is   a   pointer   to   a   user-supplied   routine   that   compares   two   array   elements   and   returns   a   value   specifying   their   relationship.   qsort   calls   the   compare   routine   one   or   more   times   during   the   sort,   passing   pointers   to   two   array   elements   on   each   call:  
   
  compare(   (void   *)   elem1,   (void   *)   elem2   );  
   
  The   routine   must   compare   the   elements,   then   return   one   of   the   following   values:  
   
  Return   Value   Description    
  <   0   elem1   less   than   elem2    
  0   elem1   equivalent   to   elem2    
  >   0   elem1   greater   than   elem2    
   
   
  The   array   is   sorted   in   increasing   order,   as   defined   by   the   comparison   function.   To   sort   an   array   in   decreasing   order,   reverse   the   sense   of   “greater   than”   and   “less   than”   in   the   comparison   function.  
   
  Example  
   
  /*   QSORT.C:   This   program   reads   the   command-line  
    *   parameters   and   uses   qsort   to   sort   them.   It  
    *   then   displays   the   sorted   arguments.  
    */  
   
  #include   <stdlib.h>  
  #include   <string.h>  
  #include   <stdio.h>  
   
  int   compare(   const   void   *arg1,   const   void   *arg2   );  
   
  void   main(   int   argc,   char   **argv   )  
  {  
        int   i;  
        /*   Eliminate   argv[0]   from   sort:   */  
        argv++;  
        argc--;  
   
        /*   Sort   remaining   args   using   Quicksort   algorithm:   */  
        qsort(   (void   *)argv,   (size_t)argc,   sizeof(   char   *   ),   compare   );  
   
        /*   Output   sorted   list:   */  
        for(   i   =   0;   i   <   argc;   ++i   )  
              printf(   "%s   ",   argv[i]   );  
        printf(   "\n"   );  
  }  
   
  int   compare(   const   void   *arg1,   const   void   *arg2   )  
  {  
        /*   Compare   all   of   both   strings:   */  
        return   _stricmp(   *   (   char**   )   arg1,   *   (   char**   )   arg2   );  
  }  
   
   
  Output  
   
  [C:\code]qsort   every   good   boy   deserves   favor  
  boy   deserves   every   favor   good  
   
   
  Searching   and   Sorting   Routines  
   
  See   Also       bsearch,   _lsearch  
  Top

4 楼ndy_w(carpe diem)回复于 2002-03-18 17:11:12 得分 0

自己写个compare函数  
  Top

相关问题

  • 求给数组排序的算法或其它方法
  • 数组算法??
  • 数组排序
  • 数组排序?
  • 数组排序?
  • ◆数组排序
  • 数组排序----急
  • 求教高手无符号整形数组递减排序,什么算法最快?谢谢!
  • 请问对于有10000左右元素的数组,用什么排序算法最快?
  • 数组长度和数组排序

关键词

  • qsort
  • sorted
  • compare
  • elem
  • routine
  • array
  • pointers
  • compatibility
  • argv
  • argc

得分解答快速导航

  • 帖主:wangjiandy
  • ndy_w

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
惹火投票。。火热进行中...
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
CSDN网站24小时值班电话:13552009689
Copyright © 2000-2009, CSDN.NET, All Rights Reserved
GongshangLogo