arrays - C 编程:使用指针对数组进行排序的函数
问题描述
我在使用此功能时遇到了一些问题。其主要目的是按节数按降序对类数组(如下)进行排序。这是类的数组:
CIS_CLASSES *pCls, *pLast;
CIS_CLASSES clsList[NUM_CLS] =
{
{"CIS 35A", 2, {61, 63}},
{"CIS 35B", 1, {62}},
{"CIS 41A", 3, {1, 2, 61}},
{"CIS 28", 1, {61}},
{"CIS 22C", 4, {3, 4, 61, 63}},
{"CIS 26B", 1, {61}},
{"CIS 22B", 8, {1, 2, 3, 4, 6, 61, 62, 63}},
{"CIS 29", 1, {61}},
{"CIS 22A", 8, {1, 3, 5, 6, 7, 8, 61, 63}},
};
我还使用 struct 定义了 NUM_CLS:
#define NUM_CLS 9
typedef struct
{
char course[10];
int noSections;
int sections[16];
int final;
} CIS_CLASSES;`
这是功能:
void sortDescend(CIS_CLASSES list[], CIS_CLASSES *pLast);
{
CIS_CLASSES *pCurr;
CIS_CLASSES *pWalk;
for (pCurr = list- 1; pCurr < pLast; pCurr++)
{
CIS_CLASSES temp = *pCurr;
pWalk = pCurr - 1;
while (pWalk >= 0 && temp.final > pLast->list[pWalk].final)
{
pLast->list[pWalk + 1] = pLast->list[pWalk];
pWalk--;
}
pLast->list[pWalk + 1] = temp;
}
}
}
当我尝试运行此代码时,我收到错误消息:“CIS_CLASSES”中没有名为“list”的成员。但我不明白为什么?我怎样才能让它运行?如果我遗漏了什么,请告诉我!
解决方案
查看您的结构,我看不到list
那里的元素:
typedef struct
{
char course[10];
int noSections;
int sections[16];
int final;
} CIS_CLASSES;
所以
pLast->list[pWalk].final
必须失败。
推荐阅读
- c# - 需要帮助从对象列表中获取 Linq 中的数组
- android - P-Nucleo STM32WB55 蓝牙 BLE 传感器演示应用
- android - 华为推送工具包 API - 使用本机反应读取后台推送数据消息
- c++ - LibCurl-如何更新已设置的特定标头信息?
- c# - iOS Safari 上禁止使用 ASP.NET Core 3.1
- c# - 基于 Find at another table 进行更新
- azure-devops - Azure Devops - 删除挂起的 helm 升级
- javascript - 覆盖函数内部的类的方法
- azure-pipelines - 是否有将任务组打包为 Azure DevOps 扩展(任务)的简单方法?
- python - Python ProcessPool 和 Pandas read_sql