Answer the question
In order to leave comments, you need to log in
How to implement a tree based on a linked list?
It is necessary to implement a tree based on a linked linear list. As much as possible?
Answer the question
In order to leave comments, you need to log in
In general, a tree and a list are not isomorphic to each other. The tree has a hierarchy. A tree cannot be implemented with a list (single).
Perhaps you need to store the children of each vertex as a linked list (then you will have a bunch of lists). Also, a popular approach (actually doing the same thing) is to store at each node a reference/pointer to the first child and the next sibling. So all the lists will be mixed into one big structure. But here, however, unlike the linked list, there are still 2 types of links.
Each element of the list can have either one successor or zero. You probably need to implement on pointers.
If you really need it directly on lists, then you can number the elements of the list and store descendants in each.
Something like this:
list:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question