把有十个元素的数组用冒泡排序法按升序排列。
#include<iostream>
using namespace std;
void bubble(int v[],int size);
int main()
{
int vn[] = {53,3,7,5,31,16,9,75,29,36};
int len = sizeof(vn)/sizeof(int);
for(int i =0;i<len;i++)
cout<<vn[i]<<",";
cout<<endl<<endl;
bubble(vn,len);
return 0;
}
void bubble(int v[],int size)
{
int temp;
for(int p=1;p<size;p++)
{
for(int i=0;i<size-p;i++)
if(v[i]>v[i+1])
{
temp = v[i];
v[i] = v[i+1];
v[i+1] = temp;
}
for(int i=0;i<size;i++)
cout<<v[i]<<",";
cout<<endl;
}
}