您的位置:首页 > 其它

例题6--2//运用直接 选择排序法对整数数组元素按照从小到大顺序排序

2012-05-03 12:54 387 查看
//运用直接 选择排序法对整数数组元素按照从小到大顺序排序
#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~~~~哪位大神能帮帮忙
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐