简单的利用了一个标志量:
#include <iostream>
#include <cstdio>
int main(void)
{
int arr[] = {65,42,13,65,73,75,2,34};
int flag = 0;
int temp =0;
int n = sizeof(arr)/sizeof(int);
// printf("%d\n",n);
for (int i=0; i<n-1; ++i)
{
flag = 1;
for (int j=0; j<n-i-1; ++j)
{
if (arr[j] > arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
flag = 0;
}
if (1 == flag)
{
continue;
}
}
}
for (int i=0; i<n; ++i)
printf("%d ",arr[i]);
printf("\n");
return 0;
}