![](https://img-blog.csdn.net/20131121094206703?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3VuYm95aXJpcw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
// sf9.cpp : 定义控制台应用程序的入口点。
//http://blog.csdn.net/sunboyiris
#include "stdafx.h"
#include "iostream"
#include "time.h"
using namespace std;
#define MAX 1000
#define SWAP(x,y) {int t;t=x;x=y;y=t;}
void bubblesort(int []);//冒泡排序
void bubblesort(int num[])
{
int i,j,k,f=1;
for(i=0;(i<MAX-1)&&(f==1);i++)
{
f=0;
for(j=0;j<MAX-i-1;j++)
{
if(num[j+1]<num[j])
{
SWAP(num[j+1],num[j]);
flag=1;
}
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int num[MAX]={0};
int i;
srand(time(NULL));
for(i=0;i<MAX;i++)
{ num[i]=rand()%100;}
bubblesort(num);
for(i=0;i<MAX;i++)
{ cout<<num[i]<<" ";}
return 0;
}