We can use bubble, quick row, select and other sorting methods to achieve array sorting, but sometimes we do not want to change the order of the array, just want to know its order, and then its subscript output, how should be implemented.
Simple example:
int num[] = {9, ten, 7, 2, 8, 3, 4, 5, 1, 6};
int flag[10]; The subscript corresponding to the value of the element from large to small, for example flag[0] 10 subscript 1 for
(int j = 0; J <; J + +) {
int max = 0, min = 0;
for (int i = 0; i < i++) {
if (Num[i] > Num[max]) {
max = i;
}
if (Num[i] < num[min]) {
min = i;
}
}
printf ("%d%d%d\n", Max, Min, num[min]);
FLAG[J] = max;
Num[max] = num[min]-ten;
printf ("%d\n", Num[max]);
}
for (int i = 0; i < i++) { //The flag is traversed sequentially to get a value from a large to a small subscript
printf ("%d", Flag[i]);
}
Write the following code into the function Xiabiao_sort:
void Xiabiao_sort (int num[], int n) {
int flag[n];
for (int j = 0; J < N; j + +) {
int max = 0, min = 0;
for (int i = 0; i < n; i++) {
if (Num[i] > Num[max]) {
max = i;
}
if (Num[i] < num[min]) {
min = i;
}
}
FLAG[J] = max;
Num[max] = num[min]-ten;
}
for (int i = 0; i < i++) {
printf ("%d", Flag[i]);}
}