#include
<
iostream.h
>
// 输出函数
int Output( int b[], int length)
{
for (int i=0;i<length;i++)
{
cout<<b[i]<<" ";
}
cout<<endl;
return 1;
}
// 冒泡算法
void BubbleSort( int arr[], int nLen)
{
for (int i=0;i<nLen;i++)
{
for (int j=0;j<nLen-i-1;j++)
{
if (arr[j]>arr[j+1])
{
int y=arr[j];
arr[j]=arr[j+1];
arr[j+1]=y;
}
}
}
}
void main()
{
//int a[]={4,1,3,2,5};
//动态输入待排序数组
int nLength;
cout<<"Enter the numble of nData: nLength=";
cin>>nLength;
cout<<endl<<"Enter nData(nLength values):";
int* nData=new int[nLength];
for (int i=0;i<nLength;i++)
{
cin>>nData[i];
}
cout<<endl<<"former:"<<endl;
Output(nData,nLength);
cout<<endl<<"later:"<<endl;
BubbleSort(nData,nLength);
Output(nData,nLength);
}
// 输出函数
int Output( int b[], int length)
{
for (int i=0;i<length;i++)
{
cout<<b[i]<<" ";
}
cout<<endl;
return 1;
}
// 冒泡算法
void BubbleSort( int arr[], int nLen)
{
for (int i=0;i<nLen;i++)
{
for (int j=0;j<nLen-i-1;j++)
{
if (arr[j]>arr[j+1])
{
int y=arr[j];
arr[j]=arr[j+1];
arr[j+1]=y;
}
}
}
}
void main()
{
//int a[]={4,1,3,2,5};
//动态输入待排序数组
int nLength;
cout<<"Enter the numble of nData: nLength=";
cin>>nLength;
cout<<endl<<"Enter nData(nLength values):";
int* nData=new int[nLength];
for (int i=0;i<nLength;i++)
{
cin>>nData[i];
}
cout<<endl<<"former:"<<endl;
Output(nData,nLength);
cout<<endl<<"later:"<<endl;
BubbleSort(nData,nLength);
Output(nData,nLength);
}