[英]Linked List of Linked List Implementation
我最近查看了可保存大量数据的链表。 但是,我坚持提出一种很好的方法来为链接列表的链接列表保存数据。
以下是我尝试完成的伪代码
struct Student
{
string Name;
}
struct Classroom
{
string Teacher;
<list> Student *student;
};
struct School
{
string School_Name;
<list> Classroom *room;
};
struct State
{
string State_Name;
<list> School *school;
};
我想知道这是否可以在链接列表中实现链接列表。 因此,当我通读XML文件时。 我可以在一个州下分配多个学校,并在一个学校中分配多个教室,依此类推。
实施总是取决于你试图解决什么问题。 在不了解问题本质的情况下,很难说您的实现是否最佳。 这绝对是合法的(尽管我会使用实际列表作为成员而不是指向列表的指针-后者似乎没有令人信服的理由)。 您的数据一次写入多次吗? 您是否希望按顺序阅读所有学生(例如)? 您是否打算经常增加新学生? 根据这些答案,可以选择程序中的最佳表示形式。
仍然可以使用上面的伪代码。
只是一个小例子:
list<list<int>> MainList; //you create a list that will contain lists
list<int> SecondList; //Let's say that you have an ordinary list
SecondList.push_back(1);
SecondList.push_back(2); //And also let's say that you enter some values in it
//Then you just add that list to the main list
MainList.push_back(SecondList); //Because MainList should contain other lists.
我希望你需要。 如果我对问题的理解不正确,对不起。 正如@Alexander L. Belikoff所说,这取决于您要解决的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.