# 指针问题 —— 排序问题

//将程序需要的代码补全，只提交begin到end部分的代码

#include <stdio.h>
#define N 10
int main()
{
int a[N],b[N],cnt=1,i,j,tmp;
int *p,*p1;
for(p = a, p1=b ;p < a+N;p++){
scanf("%d",p);
*(p1++) = cnt++;
}
for(i = 0;i < N ;i++)
for(j = i+1 ;j < N ;j++){
if(*(a+i) > *(a+j)){
tmp = *(a+i);
/********begin*********/
/*********end********/
*(b+j) = tmp;
}
}
for(p=a;p<a+9;p++)
printf("%d ",*p);
printf("%d\n",*p);
for(p=b;p<b+9;p++)
printf("%d ",*p);
printf("%d\n",*p);
return 0;
}

``1 2 3 5 4 6 8 9 10 7``

``````1 2 3 4 5 6 7 8 9 10
1 2 3 5 4 6 10 7 8 9``````

``````#include <stdio.h>
int main()
{
int a[10], loc[10];
int i, j, t;
for (i=0; i<10; i++){
scanf("%d", a+i);
loc[i] = i+1;
}
for (i=0; i<10; i++)
for (j=i+1; j<10; j++){
if (a[i] > a[j]){
t = a[i]; a[i] = a[j]; a[j] = t;
t = loc[i]; loc[i] = loc[j]; loc[j] = t;
}
}
for (i=0; i<9; i++)
printf("%d ", a[i]);
printf("%d\n", a[9]);
for (i=0; i<9; i++)
printf("%d ", loc[i]);
printf("%d\n", loc[9]);
return 0;
}

``````

``````#include <stdio.h>
int main()
{
int a[10], loc[10];
int i, j, t;
for (i=0; i<10; i++){
scanf("%d", a+i);
loc[i] = i+1;
}
for (i=0; i<10; i++)
for (j=i+1; j<10; j++){
if (a[i] > a[j]){
t = a[i]; a[i] = a[j]; a[j] = t;
t = loc[i]; loc[i] = loc[j]; loc[j] = t;
}
}
for (i=0; i<9; i++)
printf("%d ", a[i]);
printf("%d\n", a[9]);
for (i=0; i<9; i++)
printf("%d ", loc[i]);
printf("%d\n", loc[9]);
return 0;
}

``````

1. a说道：