快速排序、冒泡排序
2011-01-18 08:39
260 查看
快速排序:
int Partition(int aValue[10], int low, int high) //完成一趟快速排序
{
int pivot = aValue[low];
while (low < high)
{
while (low < high && aValue[high] >= pivot)
{
high--;
}
int tmp = aValue[high];
aValue[high] = aValue[low];
aValue[low] = tmp;
while (low < high && aValue[low] <= pivot)
{
low++;
}
tmp = aValue[high];
aValue[high] = aValue[low];
aValue[low] = tmp;
}
return low;
}
void MySort(int aValue[10], int low, int high) //递归整个排序
{
if (low < high)
{
int pivot = Partition(aValue, low, high);
MySort(aValue, low, pivot-1);
MySort(aValue, pivot+1, high);
}
}
冒泡排序:
int Partition(int aValue[10], int low, int high) //完成一趟快速排序
{
int pivot = aValue[low];
while (low < high)
{
while (low < high && aValue[high] >= pivot)
{
high--;
}
int tmp = aValue[high];
aValue[high] = aValue[low];
aValue[low] = tmp;
while (low < high && aValue[low] <= pivot)
{
low++;
}
tmp = aValue[high];
aValue[high] = aValue[low];
aValue[low] = tmp;
}
return low;
}
void MySort(int aValue[10], int low, int high) //递归整个排序
{
if (low < high)
{
int pivot = Partition(aValue, low, high);
MySort(aValue, low, pivot-1);
MySort(aValue, pivot+1, high);
}
}
冒泡排序:
<pre name="code" class="cpp"> for (i = 0; i < m; i++) { for (j = 0; j < m - i - 1; j++)//注意减1 { if (sta[j] > sta[j+1]) { nTmp = sta[j]; sta[j] = sta[j+1]; sta[j+1] = nTmp; } } }
相关文章推荐
- 快速排序,选择排序,冒泡排序
- JAVA-冒泡排序,归并排序,快速排序,堆排序学习
- #笔记#圣思园 JavaSE 第35讲——冒泡排序、交换排序、快速排序、二分查找
- javascript的冒泡排序, 快速排序, 选择排序, 插入排序
- python 实现插入排序,冒泡排序,快速排序,选择排序
- 七大内部排序算法总结(插入排序、希尔排序、冒泡排序、简单选择排序、快速排序、归并排序、堆排序)
- PHP常用排序算法实例小结【基本排序,冒泡排序,快速排序,插入排序】
- 插入排序、冒泡排序、选择排序、Shell排序、快速排序、归并排序、堆排序
- Java-冒泡排序、快速排序、插入排序、快速排序
- java 冒泡排序、快速排序
- 算法---冒泡排序,快速排序,二分查找(折半查找),选择排序,插入排序
- 6种排序算法及其比较 简单选择排序,堆排序,简单插入排序,希尔排序,冒泡排序,快速排序,归并排序
- 常见排序集合(冒泡排序,选择排序,直接插入排序,二分插入排序,快速排序,希尔排序,归并排序)
- Java排序:冒泡排序、快速排序、堆排序
- 冒泡排序,选择排序,快速排序
- 排序算法(2)冒泡排序,快速排序,归并排序和基数排序MSD,LSD
- 冒泡排序与快速排序
- 几种基本的排序算法(选择排序,冒泡排序,快速排序,归并排序,希尔排序)C语言实现
- 七大内部排序算法总结(插入排序、希尔排序、冒泡排序、简单选择排序、快速排序、归并排序、堆排序)
- 直接插入排序、希尔排序、冒泡排序、快速排序