满意答案
wyckings
推荐于 2017.12.16
采纳率:45% 等级:12
已帮助:4611人
你的基础上改5261的
#include
#include
using namespace std;
void app(int*a, int*b, int n);
int main()
{
int n, i=0;
cout << "请输入数组元4102素个数" << endl;
cin >> n;
int*a = new int[n];
int*b = new int[n];
cout << "请输入各元素" << endl;
while (i < n)
{
1653cin >> a[i];
b[i] = i;
i++;
}
app(a,b,n);
cout << "排序后:" << endl;
for (i = 0; i
cout << setw(5) <
cout << endl;
for (i = 0; i
cout << setw(5) << b[i];
cout << endl;
system("pause");
return 0;
}
void app(int*a, int*b, int n)
{
int i, j,t, temp;
for (i = 0; i < n - 1;i++)
{
t = i;
for (j = i + 1; j < n; j++)
if (a[j] < a[t]) t = j;
if (t != i)
{
temp = a[i];
a[i] = a[t];
a[t] = temp;
temp = b[i];
b[i] = b[t];
b[t] = temp;
}
}
}
你的主函数是int的没有返回值 赋值过程也错了 app函数变量i跟j重定义了。你参考参考吧
00分享举报