//运用直接 选择排序法对整数数组元素按照从小到大顺序排序
#include<iostream.h>
#define SIZE 8
int main()
{
int a[SIZE]={18,35,36,61,9,112,77,12};
//输出原数组
for(int i=0;i<=SIZE-1;i++)
cout<<a[i]<<endl;
//对数组进行排序
for(int pass=0;pass<=SIZE-1;pass++)
{
for(int j=pass+1;pass<=SIZE-1;j++)
if(a[pass]>a[j])
{
int hold;
//交换
hold=a[pass];
a[pass]=a[j];
a[j]=hold;
}
//输出当前的结果
cout<<"After NO."<<pass+1<<"scan:";
for(int index=0;index<=SIZE-1;index++)
if(index==pass+1) //index的值是输出元素位置,pass是输出的行数。
cout<<"\t"<<"["<<a[index];
else
cout<<"\t"<<a[index];
cout<<"]"<<endl;
}
cout<<"After sorting:\t";
for(int index=0;index<=SIZE-1;index++)
cout<<"\t"<<a[index];
cout<<endl;
return 0;
}
不知道为什么,程序运行时总是提醒内存不能Read~~~~哪位大神能帮帮忙