冒泡排序可以这样写吗,我只对结构体数组中某一个元素进行排序,然后交换

struct troop
{
char name[1];
int a[3];
}tro[4];

void bubblesort(int a, int b, int c)
{
struct troop temp;
int i, j;
for (i=a; i {
for (j=a+1; j {
if (tro[j].a[c] > tro[i].a[c])
{
temp = tro[j];
tro[j] = tro[i];
tro[i] = temp;
}
}

}

}

把代码放到代码片里,工具栏上面有。否则粘贴错误太多。

把你代码编译下有错误

 void bubblesort(int a, int b, int c)
{
    struct troop temp;//错误  不允许使用不完整的类型   
    int i, j;
    for (i=a; i<-;i++)
    {
        for (j=a+1; j<-;j++)
        {
            if (tro[j].a[c] > tro[i].a[c])//错误 “tro”: 未声明的标识符 

            {
            temp = tro[j];
            tro[j] = tro[i];
            tro[i] = temp;
            }
        }
    }
}

你的结构体后面那个tro[4]是什么意思?是多个结构体组吗?

只对一个交换
{
这里面应该就是结构体数组咯
}
可以这样