C++排序程序不成功啊;;;;

[复制链接]
查看11 | 回复3 | 2011-11-12 22:55:30 | 显示全部楼层 |阅读模式
你的这个排序,swap(&aray,&array[smallest])位置错了:应该放在内层for之外,以下这个是经典的选择排序你也可以参考下void selectsort(int *a,int len){
int i,j,k;
for(i=0;ia[j])
k=j;
}
swap(&a,&a[k]);
}}...
回复

使用道具 举报

千问 | 2011-11-12 22:55:30 | 显示全部楼层
swap( &array[ i ], &array[ smallest ] );放在第2个for循环外面。for ( int i = 0; i < size - 1; i++ ){smallest = i; // first index of remaining array// loop to find index of smalle...
回复

使用道具 举报

千问 | 2011-11-12 22:55:30 | 显示全部楼层
在VC++6下,你把一个“}”放错地方了。#include using std::cout;using std::endl;#include using std::setw;void selectionSort( int * const, const int ); // prototypr...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行