C语言实现的快速排序算法的代码

2019-04-28  本文已影响0人  hahamama

工作期间,将开发过程中经常用到的代码片段记录起来,如下代码段是关于C语言实现的快速排序算法的代码,应该对各朋友也有用处。

#include <stdlib.h>

#include <stdio.h>

  while(l--) {

  }

}

  if (end > begin) {

      int l = begin + size;

      int r = end;

      while(l < r) {

        if (cmp(array+l,pivot) <= 0) {

            l += size;

        } else {

            r -= size;

            swap(array+l, array+r, size);

        }

      }

      l -= size;

      swap(array+begin, array+l, size);

      sort(array, size, cmp, begin, l);

      sort(array, size, cmp, r, end);

  }

}

}

typedef int type;

  int num_list[]={5,4,3,2,1};

  int len=sizeof(num_list)/sizeof(type);

  int i;

  qsort(num_list,len,sizeof(type),type_cmp);

  printf("sorted_num_list={");

  for(i=0; i<len; i++){

    printf("%s%d",sep,num_list[i]);

    sep=", ";

  }

  printf("};n");

}

上一篇 下一篇

猜你喜欢

热点阅读