冒泡算法

include

using namespace std;
//Function prototype
int* selectSort(int ,int);
void showArray(const int [],int);
int main()
{
int array[] = {7,2,4,5,9,10};
int size = sizeof(array)/sizeof(array[0]);//求数组的长度
showArray(array,size);
selectSort(array,size);
showArray(array, size);
cout < return 0;
}
int
selectSort(int p,int size)
{
int temp;
int swap;
do
{
swap = false;
for (int i = 0; i < (size - 1);i++)
{
if (
(p+i) > (p +i+ 1))
{
temp =
(p+i);
(p + i) = (p + i + 1);
*(p + i + 1) = temp;
swap = true;
}
}

} while (swap);
return p;

}
void showArray(const int array[], int size)
{
for (int count=0;count {
cout << array[count] <<" ";
}
cout << endl;
}

你可能感兴趣的:(冒泡算法)