Re: convert a list to tree
prabhat143@gmai l.com writes:[color=blue]
> Question is the list says: list is not sorted and it is null
> terminated. By tree, it does not mean a binary tree.It could be n-ary
> tree. Each node in the list knows its ID and its parent ID. The root of
> the resulting tree which could be anywhere in list has its parent ID 0.[/color]
Please don't top-post.
This smells like homework.
What's an "ID", and how is it relevant to the problem?
If the tree doesn't have to be binary, the problem is trivial.
A linked list is already an n-ary tree (n=1).
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
prabhat143@gmai l.com writes:[color=blue]
> Question is the list says: list is not sorted and it is null
> terminated. By tree, it does not mean a binary tree.It could be n-ary
> tree. Each node in the list knows its ID and its parent ID. The root of
> the resulting tree which could be anywhere in list has its parent ID 0.[/color]
Please don't top-post.
This smells like homework.
What's an "ID", and how is it relevant to the problem?
If the tree doesn't have to be binary, the problem is trivial.
A linked list is already an n-ary tree (n=1).
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Comment