6个回答

`````` #include <iostream>
using namespace std;
class A
{
public:
void print(int* pData, int count){
for (int i = 0; i< count; i++) {
cout << pData[i] << " ";
}
cout << endl;
}

void BubbleSort(int* pData, int count)
{
int temp;
for (int i = 1; i < count; i++)
{
for (int j = count - 1; j >= i; j--)
{
if (pData[j] < pData[j - 1])
{
temp = pData[j - 1];
pData[j - 1] = pData[j];
pData[j] = temp;
}
}
cout << "The "<< i <<" round:" << endl;
print(pData, count);
cout << "----------------------------" << endl;
}
}
};
int main()
{
int data[] = {10, 8, 9, 7, 4, 5};
A a;
a.BubbleSort(data, 6);
cout << "The sort result:" << endl;
a.print(data, 6);
return 0;
}
``````

#include
#include
using namespace std;

int main(){
int arr_size;
cin>>arr_size; //确定需要输入的数字有多少个
int arr[arr_size];
cout<<"please enter the number sequence: ";
for (int i=0;i cin>>arr[i];
sort(arr,arr+arr_size); //调用STL的排序算法

``````    //display
cout<<"after sort: ";
for (int i=0;i<arr_size;++i)
cout<<arr[i]<<" "<<endl;

return 0;
``````

}

mall_lucy 不用sort行不