恭喜,你发布的帖子
发布于 2023-07-21 15:34:27
4楼
char *pTags[] = {"T1", "T2", "T3", "T4", "T5", "T6", "T7", "T8", "T9", "T10"}; //变量数组
char *pSortedTags[] = {"s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10"}; //显示用的变量数组
char *pSortedNames[] = {"n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9", "n10"}; //显示用的名称数组
int values[10] = {13, 83, 33, 54, 90, 38, 42, 34, 89, 22};
int index[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int i = 0;
int j = 0;
int temp = 0;
for(i = 0; i != 9; ++i)
{
for(j = i + 1; j != 10; ++j)
{
if(values[i] < values[j])
{
temp = index[i];
index[i] = index[j];
index[j] = temp;
temp = values[i];
values[i] = values[j];
values[j] = temp;
}
}
}
for(i = 0; i!= 10; ++i)
{
printf("i = %d, %d, %d ", i, index[i], values[i]);
}
printf(" ");
return 0;
如上, index可以用来标记索引, 这样显示的时候就指导该怎么显示了。
请填写推广理由:
分享
只看
楼主