# include "tree.h"

/* CREATE NODE: returns a pointer to a newly created and initialized
                node with symbolic name 'symbol'                       */

struct node *create_node(symbol)
char *symbol;
{

int i;
struct node *new_node;

new_node = (struct node *) malloc(sizeof(struct node));
new_node->symbol=(char *) malloc(strlen(symbol)+1);
strcpy(new_node->symbol,symbol);

new_node->num_children=0;

return new_node;}


/* ADD_CHILD: inputs a pointer to a parent and child node
              assigns the child pointer to the parent       */

void add_child(parent,child)

struct node *parent;
struct node *child;{

if (parent->num_children<(Max_Children-1)){
   parent->children[parent->num_children]=child;
   parent->num_children++;}

return;}


/* PRINT TREE: prints out the tree with root pointed to by 'root'
               recursively calls print_tree to print all children
	       tabs over once for each level in the tree            */

void print_tree(root,tab_num)

struct node *root;
int tab_num;{

int i;

for (i=0;i<tab_num;i++)
   printf(" ");

printf("%s\n",root->symbol);

for (i=0;i<root->num_children;i++)
   print_tree(root->children[i],tab_num+1);

return;}

