在c++中实现嵌套链表
implementing nested linked list in c++
这种嵌套链表的实现在c++中有效吗?如果是,那么如何声明嵌套链表的头?访问里面那些列表中的数据的语法是什么?这是我的通用代码的一部分。我正在尝试用c++执行一个库管理系统。
struct course
{
string course_name;
struct course_books
{
struct wait_list
{
long stu_num;
//date inserted
wait_list * next_wait_stu;
};
struct voters_list
{
long stu_num;
int vote;
voters_list * next_voter;
};
struct deposit_list
{
long stu_num;
//date given
//bring back date
deposit_list * next_depositor;
};
};
course * next_course;
};
struct demand
{
int ISBN;
string book_name,
course,
author,
edition;
int demands_num;
struct demanding_students
{
string demander_name;
int demander_stu_number;
//demand date
demanding_students * next_demanding_stu;
};
demand * next_demand;
};
struct STUDENT_INFO
{
struct all_deposited_books
{
int ISBN;
//date given
//bring back date
all_deposited_books * next_dep_book;
};
struct today_deposited
{
int ISBN;
today_deposited * next_today_dep_book;
};
};
您可能希望使用类来实现这一点。类似于:
class STUDENT_INFO{
protected:
struct all_deposited_books
{
int ISBN;
//date given
//bring back date
};
struct today_deposited
{
int ISBN;
};
public:
all_deposited_books * next_dep_book;
today_deposited * next_today_dep_book;
};
然后创建一个类实例,比如:STUDENT_INFO theBestStudentInfo;
,如果你想在里面调用一个结构变量,你只需要调用:theBestStudentInfo.all_deposited_books[0].ISBN = 5;
或类似的东西。我不认为你可以在结构本身内部创建一个结构实例,比如:
struct all_deposited_books
{
int ISBN;
//date given
//bring back date
all_deposited_books * next_dep_book; //<- this is probably gonna cause problems
};
首先创建结构及其外观,然后可以开始根据需要创建它的实例数量:)
相关文章:
- 反向给定链表中的K节点
- C++嵌套的迭代器类(在链表类中)Insert_After函数
- 在结构的嵌套映射上链接运算符 []
- 嵌套的类成员变量不可访问.链表设置.V、下一个和新的问题
- 将嵌套的 std::arrays 视为具有链式 .data() 的单个平面数组
- 如何链接嵌套的模板化专用化
- 我如何能够访问双向链表中的嵌套结构
- 为什么链表中的数据在嵌套函数中会更改/损坏?
- C 中的嵌套双链接列表
- 对嵌套结构单链接和双链接进行排序
- 在c++中实现嵌套链表
- 链表类,如何访问嵌套节点结构的数据
- 将错误与C++单独的头文件中定义的模板类和嵌套类链接
- 我是否正确地将嵌套的 lua 表作为 C 函数的参数
- 嵌套模板链接错误
- 带嵌套类的链表:如何在声明嵌套类类型之前使用它
- Lua C API嵌套表seg.的错
- 将嵌套表从Lua传递到C
- 删除与另一个成员相等的链表成员的嵌套循环中断.将问题隔离到一行
- 在数组链表中使用一个嵌套循环从一个位置迭代到另一个位置