数组排序c语言 并输出下标,用C++对一组数据排序并输出每个元素在原数组中的下标...

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

wyckings

推荐于 2017.12.16

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率: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分享举报

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值