In a Binary Tree, each node has two children at most. To eliminate the restricti
ID: 3540516 • Letter: I
Question
In a Binary Tree, each node has two children at most. To eliminate the restriction by linking the children
together to form a list. In this design, each node in the tree needs to contain only two pointers: one to its eldest
child and one to its next younger sibling.
Using this representation, in each node, the pointer on the left always points down to child; the pointer on the
right indicates the next sibling in the same generation.
struct node
{
char name[32];
struct node *child;
struct node *sibling;
};
typedef struct node NODE;
Using the above linked design to implement the following two functions.
1) NODE* SearchMember(NODE *tree, char *target);
that searches a node in a family tree. If it finds it, then it returns the address of the node. If not, it returns
NULL.
2) NODE* InsertMember(NODE *ptree, char *newName, char *parentName);
that searches the parent node with parentName. If found, add a new node with newName to its child list.
3) NODE* ReadFamilyTree(char *filename);
that reads in a family tree from a data file whose name is supplied as the argument to the call. The first line of
the file should contain a name corresponding to the root of the tree. All subsequent lines in the data file should
have the following form:
child:patent
where child is the name of the new individual being entered and parent is the name of that child's parent, which
must appear earlier in the data file. For example,
William I
Pobert:William I
William II:William I
Anna:William I
Henry I:William I
Steven:Anna
William:Henry I
Matilda:Henry I
Henry II:Matilda
4) void DisplayFamilyTree(NODE *tree);
that displays all the individuals in a family tree. To record the hierachy of tree, the output of your program
should ident each generation so that the name of each child appears two spaces to the right of the
corresponding parent, as shown in the following:
William I
Pobert
William II
Anna
Steven
Henry I
William
Matilda
Henry II
5) Write a test program that tests all the functions above.
Explanation / Answer
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.