Exercise 5 on Binary Tree - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Exercise 5 on Binary Tree

Description:

Bonus of 2 points if submitted on or before the due date. The Family Ancestry. Make a program that will create a binary tree of a family starting from the parents. ... – PowerPoint PPT presentation

Number of Views:94
Avg rating:3.0/5.0
Slides: 11
Provided by: rtg
Category:

less

Transcript and Presenter's Notes

Title: Exercise 5 on Binary Tree


1
Exercise 5 on Binary Tree Due Date 6
October Bonus of 2 points if submitted on or
before the due date
2
The Family Ancestry
  • Make a program that will create a binary tree
    of a family starting from the parents . The
    program should
  • Create first the root of the binary family tree
  • Add the child to either left or right. (max of 2
    children only)
  • Before inserting a surname, search first its
    parent. Use either inorder/preorder/postorder
    traversal to search.
  • The program should be able to post a comment for
    the person, i.e. dead, in USA, in the moon,
    etc..

3
Illustration
John dead, Mary
root
Anne, Roger-dead
Mike, Mary
4
Your program may have the following options
  • 1- Create parent
  • 2- Search a person
  • 3- Insert a Child
  • 4- Post a comment

5
Declaration
  • struct node
  • char name
  • char remarks
  • char partner_name
  • char partner_remarks
  • node left, right

6
Now lets write the algorithms
  • Create parent
  • Search a person
  • Insert a child
  • Post a comment

7
For 1 bonus point..give me a start..
  • function CreateParent(root)
  • root new node
  • root-name inputname
  • root-partnername partner
  • root-remarks
  • root-partner_remarks
  • return root

8
Search
  • SearchPerson(isfound,node, inputname)
  • If node !NULL
  • if node-name inputname
  • isfound true
  • return(node)
  • else
  • if not isfound
  • return(SearchPerson(node-left)
  • if not isfound()
  • return(SearchPerson(node-right)

9
Insert a Child
  • InsertChild(parentname,childname,root)
  • parent SearchPerson(isfound,root,parentname)
  • If parent NULL
  • childnode CreateChild(childname)
  • if parent-left NULL
  • parent-left childnode
  • else
  • parent-right childnode

10
Post A Comment
  • PostComment(inputname,comment,root)
  • person SearchPerson(isfound,root,inputname)
  • If person NULL then
  • person- remarks comment
Write a Comment
User Comments (0)
About PowerShow.com