我的问题是如何创建链表并且其中的每个节点都有两个指针,每个指针指向两个不同的节点,就像图片一样
http://tinypic.com/r/1444apy/5
我正在尝试创建两个类,但我不知道如何组合这些类以使每个节点都有子级
class Department
{
string name; //name of the department
int numStudents; //number of students in the department
Department* next; //this pointer will point to the next department
};
class College
{
string name; //for name of the college
int numDepartments; //number of departments in this college
Department* dep; //this will point to the department in this college
College * next; //the next pointer to point to the next college
};
答案 0 :(得分:0)
尝试将每个节点视为College
个节点 - 即每个节点都有一个指向下一个节点的指针,以及一个指向子节点的指针。对于没有子节点的节点(在您的图片上,Department
节点),只需将子节点(dep
)设置为NULL。