下面是的代码都是C++ 实现的
1.插入排序—直接插入排序(Straight Insertion Sort)
#pragma once
#include "JudgmentCondition.h"
void InsertionSort(int *arr, int arrsize, bool sortMethod)
{
int i = 0;
functionPointer fun = retfun(sortMethod);
for (int i = 1; i < arrsize; ++i)
{
int sentryPost = arr[i];
for (int j = 0; j < i; ++j)
{
if (fun(arr[j], sentryPost))
{
exchange(sentryPost, arr[j]);
}
}
exchange(arr[i], sentryPost);
}
}
- 插入排序—希尔排序(Shell`s Sort)
- 选择排序—简单选择排序(Simple Selection Sort)
- 选择排序—堆排序(Heap Sort)
- 交换排序—冒泡排序(Bubble Sort)
#pragma once
#include "JudgmentCondition.h"
void BubbleSort(int *arr, int arrsize, bool sortMethod)
{
bool isBreak;
int i = 0;
functionPointer fun = retfun(sortMethod);
while (true)
{
if (i >= arrsize - 1)
{
if (isBreak)
break;
i = 0;
isBreak = true;
}
if (fun(arr[i], arr[i + 1]))
{
exchange(arr[i], arr[i + 1]);
isBreak = false;
}
++i;
}
}
- 交换排序—快速排序(Quick Sort)
- 归并排序(Merge Sort)
- 桶排序/基数排序(Radix Sort)
没写完。。。待完善。。