赞
踩
感谢网上各位大神的讲解,参考了网上多位大神的博客,做出了这次整理。
void Swap(int* a, int* b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}
void PrintArray(int data[],int length)
{
for (int i = 0; i < length; i++)
{
cout << data[i] << " ";
}
cout << endl;
}
/*交换排序:冒泡排序*/
void bubbleSort(int data[], int length)
{
if (data == nullptr || length <= 0)
return;
for (int i = 0; i < length - 1; i++)
{
for (int j = 0; j < length - i - 1; j++)
{
if (data[j]>data[j + 1])
Swap(&data[j], &data[j + 1]);
}
}
}
/*交换排序:快速排序*/
int Partition(int data[], int length, int start, int end)
{
if (data == nullptr || length <= 0 || start < 0 || end >= length)
throw new exception("invalid parameters!");
int index = start;
int small = start - 1;
for (index; index < end; index++)
{
if (data[
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。