修改文件结构。
This commit is contained in:
44
POP/11/Exercise03.c
Normal file
44
POP/11/Exercise03.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int findIndex(int a[], int num) {
|
||||
int i = 0;
|
||||
for (i = 0; i < 10; i++) {
|
||||
if (a[i] == num) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a[10] = {0};
|
||||
int *pa[10] = {0};
|
||||
int *tmp;
|
||||
int i = 0;
|
||||
bool moved = true;
|
||||
for(i = 0; i < 10; i++) {
|
||||
pa[i] = a+i;
|
||||
scanf("%d", a+i);
|
||||
}
|
||||
while(moved) {
|
||||
moved = false;
|
||||
for (i = 0; i < 9; i++) {
|
||||
if (*pa[i] > *pa[i+1]) {
|
||||
tmp = pa[i];
|
||||
pa[i] = pa[i+1];
|
||||
pa[i+1] = tmp;
|
||||
moved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 10; i++) {
|
||||
printf("%d ", *pa[i]);
|
||||
}
|
||||
printf("\n");
|
||||
for (i = 0; i < 10; i++) {
|
||||
printf("%d ", findIndex(a, *pa[i]));
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user