C语言---快速排序算法实现
来源:互联网 发布:dbscan聚类算法 编辑:程序博客网 时间:2024/05/21 10:02
快速排序算法是冒泡排序的改进算法,其核心思想在于:通过一趟排序将一堆带排序序列分割成两个独立的序列,其中一部分记录的关键字比另一部分记录的关键字小,然后再分别对这两部分进行类似的分割,直到排序完成。重难点在:分割。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*quicksort algorithm*/
//快速排序重在分割,分割完成即排序完成;static int Partition(int data[],int low,int high)
{
int i = 0;
int j = 0;int priviorData = data[low];
while(low<high)
{
while(low<high&&data[high]>=priviorData)
{
--high;
}
data[low] = data[high];
while(low<high&&data[low]<=priviorData)
{
++low;
}
data[high] = data[low];
}
data[low] = priviorData;
return low;//return privior index position
}
static void QuickSort(int data[],int low,int high)
{
int priviorIndex = low;
if(low<high)
{
priviorIndex = Partition(data,low,high);
QuickSort(data,low,priviorIndex-1);
QuickSort(data,priviorIndex+1,high);
}
}
static void showArry(int data[],int length)
{
int k = 0;
for(k=0;k<6;k++)
{
printf("x[%d] = %d , ",k,data[k]);
}
printf("\n\n");
}
void main()
{
int k = 0;
int x[] = {9,6,5,3,10,2};
showArry(x,6);
QuickSort(x,0,5);
showArry(x,6);
}
0 0
- 快速排序C语言算法实现
- c语言实现快速排序算法
- 快速排序算法的c语言实现
- 快速排序算法的C语言实现
- 算法导论C语言实现: 快速排序
- 快速排序算法 C语言实现
- 直白快速排序算法,C语言实现
- C语言快速排序算法实现
- 【算法】C语言实现的快速排序
- C语言实现数组快速排序算法
- C语言---快速排序算法实现
- 快速排序算法的C语言实现
- C语言实现快速排序算法
- 用C语言实现快速排序算法
- 用C语言实现快速排序算法
- 快速排序算法的C语言实现
- C语言实现快速排序算法
- 快速排序算法-C语言实现
- Android Context详解
- iOS经典讲解之实现扫描二维码ZBarSDK的使用
- 学习札记
- Android 开源库StickyListHeadersListView来实现ListView列表分组效果
- java分层架构概念
- C语言---快速排序算法实现
- c++基础要点整理(二)之——友元
- RESTful Web Services
- git操作入门
- 虚拟机与宿主机的连接
- js和jquery获取父级元素、子级元素、兄弟元素的方法
- 嵌入式程序员应该知道的16个问题
- 《leetCode》:Container With Most Water
- 学习笔记之STM32F429 Discovery开发环境构建