// 数组两边分边排序, in place merge 数组,使得整个数组有序.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
void swap(int &A, int &B)
{
int tmp = A;
A = B;
B = tmp;
}
void reSortArray(int Array[], int halfPartPos, int totalLen)
{
int comparedPos = halfPartPos;
for (int idx = comparedPos; idx < totalLen; idx++)
{
for (int jdx = 0; jdx < idx; jdx++)
{
if (Array[jdx] > Array[idx])
swap(Array[jdx], Array[idx]);
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int Array[] = {1,3,6,8,11, -5,-2,4,7,9};
reSortArray(Array, 5, 10);
return 0;
}
数组两边分边排序, in place merge 数组,使得整个数组有序
最新推荐文章于 2022-08-05 01:04:33 发布