Reading binary tree from a file

How to read a binary tree from a file

Page 1 of 1

2 Replies - 6056 Views - Last Post: 07 September 2010 - 10:00 AM Rate Topic: -----

#1 Guest_Abhi*


Reputation:

Reading binary tree from a file

Posted 07 September 2010 - 05:23 AM

Hi guys,
The inforamtion below is given in a file, and You have to make a function to rebuild the binary tree in C++..

node leftchild rtchild

1 2 4
2 $ 5
5 6 7
6 $ $
7 $ $
4 $ 8
8 $ $

$- Empty

I'm not asking to write the code...
just suggest me some algorithm for this..

Can anyone suggest some idea to rebuild the binary tree...???

Is This A Good Question/Topic? 0

Replies To: Reading binary tree from a file

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Reading binary tree from a file

Posted 07 September 2010 - 09:56 AM

Look up binary trees and algorithms for working with binary trees.
Was This Post Helpful? 0
  • +
  • -

#3 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,140
  • Joined: 14-September 07

Re: Reading binary tree from a file

Posted 07 September 2010 - 10:00 AM

I'd start here

As for the file:

Read the entire first line.
Then visit the lines of the two nodes of '1'
Repeat until you've filled the tree.

Alternatively, I would construct the tree by hand. Read a line, draw the applicable nodes. Then figure how you would "tell" the computer to do what you just did by hand.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1