对嵌套结构单链接和双链接进行排序
sort nested struct single linked and double
我嵌套为:
typedef struct a{
const char * LongName;
const char * ShortName;
int a;
struct a * next;
}Level5;
typedef struct a1{
const char * LongName;
const char * ShortName;
int frequency5;
int id;
Level5 * linked;
struct a1* next_a1;
}Level4;
typedef struct a2{
const char * Name;
int frequency4;
Level4 * linked;
int id;
struct a2 * next;
}Level3;
typedef struct a3{
const char * LongName;
const char * ShortName;
int frequency3
int id;
Level3 * linked;
}Level2;
typedef struct a4{
const char * LongName;
const char * ShortName;
_Bool top;
int id;
int frequency2;
Level2 * lined;
}Level1;
typedef struct cat{
int id;
const char * CatName;
Level1 * linked;
}CAT;
CAT total[256];
现在我想对链接的嵌套结构结构进行排序,如下所示:
1. Level 5 -> LongName
2. Level 4 -> ShortName
3. Level 3 -> Name
4. Level 2 -> Frequency3
Level 1
|
| Level 2
====================================================
| Level3 |Level3 |level 3
=============
| next next
level4 -> lev4 -> lev4
| |
| =====================================
=============================== |
| next next Level5 -> level5 -> level5
Level5 -> Level5 -> level5
看起来您具有以下数据结构:
Level5 node --> Level5 node --> Level5 node
|
v
Level4 node --> Level4 node --> Level4 node
|
v
Level3 node --> level3 node --> Level3 node
|
v
Level2 node --> level2 node --> Level2 node
如果是这种情况,可以简化数据结构:
struct Node
{
};
struct Node_Row
{
unsigned int level;
std::list<Node> nodes_in_row;
};
struct data_structure
{
std::list<Node_Row> levels;
};
您应该有一个对行进行排序的比较器函数和另一个对级别进行排序的比较器函数。
另外,由于您将问题标记为C++,因此您应该省去一些麻烦并使用std::string
而不是char *
。 std::string
为您管理动态内存分配和释放,而char *
管理内存分配和释放。
相关文章:
- 是否可以在调用链接器时强制 CMake 重新排序参数?
- 两个排序的链接列表C 的交点
- 双链表中按字母顺序排序的链接
- 排序阵列会使指针链接错误
- 初学者C 排序的链接列表使用=操作员进行深层复制
- 合并对链接列表进行排序
- 自定义排序实现会导致链接错误
- 在C 中对多个链接数组进行排序
- 分段故障:链接列表上的气泡排序
- 读取中的链接列表,然后按名称进行排序
- 对嵌套结构单链接和双链接进行排序
- 链接相互引用的排序类。转发不起作用
- 合并两个排序的链接列表
- 重新排序GNU Autotools链接器标志
- 通过修改链接来对链接列表进行排序
- 排序C 中的链接列表
- 在已排序的双链接列表中插入节点
- 带跳过列表的双链接列表,以排序方式插入
- 在链接列表上执行合并排序
- 插入排序以对链接列表中的节点进行排序