冒泡排序基础版
重复地走访过要排序的元素列,依次比较两个相邻的元素,如果顺序错误就交换二者的值,这样每次走访完一次就相对有序一次,依次循环即可,当进行至多n-1(n为数组元素个数)次即可完成排序。
#include<iostream>
#include<malloc.h>
using namespace std;
void BubbleSort(int arr[],int nLength)
{
if(arr == NULL || nLength <= 0) return;
int i, j;
for(i = 0; i < nLength - 1; i++)
{
for(j = 0; j < nLength - 1 - i; j++)
{
if(arr[j] > arr[j+1])
{
arr[j]