| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
A file format for writing a tree structure into a file
Hi,
I've created a tree using VC++. i would like to write the tree structure to a text file. Can anyone suggest me a format for writing into a file??? It should be in such a way that the tree can be easily recreated by reading from the text file....Help please..... ![]() |
|
#2
|
||||
|
||||
|
I'd recommend doing somethine like this.
Write each level of your tree in it's own block, seperated by newlines (if you have an empty node then fill with a question mark or something).... For example, if you have this tree: Code:
1
2 3
4 5 6
7 8 9
you could right it as: Code:
1 2 3 4 5 ? 6 7 8 ? 9 ? ? ? ?
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
|
#3
|
|||
|
|||
|
But how will i know whether '1' is a root node or '2' is a root node??
|
|
#4
|
|||
|
|||
|
s01: Do you want pictorial representation of your tree or as a linear array?
If B-con's example is taken, and you wanna know your root, choose any ordering of tree while putting in text file. There are 3 ways in which a tree can be traveresed. Then , input will be : 1 2 4 5 3 7 6 in preorder. Clearly, root will be : 1 its left child as 2 , now taking 2 as center, 4 and 5 come under it, when subtree centered at 2 is completed, go to 4 etc.... Aplly the principal: CLR. Remember, a unique tree is constructed from Pre-order and post -order. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > A file format for writing a tree structure into a file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|