Exemple #1
0
int main(int argc, char *arv[])
{
	Node_t *p = NULL;
	TreeNode_t *t = NULL;

	// Linked list
	printf("List contains %d nodes\n", list_count(p));
	list_display(p);

	list_append(&p, 10);
	printf("List contains %d nodes\n", list_count(p));
	list_display(p);

	list_append(&p, 20);
	list_append(&p, 30);
	list_append(&p, 40);
	list_append(&p, 50);
	printf("List contains %d nodes\n", list_count(p));
	list_display(p);

	list_remove(&p, 20);
	printf("List contains %d nodes\n", list_count(p));
	list_display(p);

	list_remove(&p, 123);

	list_remove(&p, 10);
	list_remove(&p, 30);
	list_remove(&p, 50);
	list_remove(&p, 40);
	printf("List contains %d nodes\n", list_count(p));
	list_display(p);

	list_remove(&p, 100);


	// Binary tree
	tree_display(t);
	printf("\n");

	tree_insert(&t, 10);
	tree_display(t);
	printf("\n");

	tree_insert(&t, 8);
	tree_insert(&t, 11);
	tree_display(t);
	printf("\n");

	tree_insert(&t, 4);
	tree_insert(&t, 3);
	tree_display(t);
	printf("\n");

	tree_insert(&t, 15);
	tree_insert(&t, 14);
	tree_display(t);
	printf("\n");
	return 0;
}
Exemple #2
0
void
tree_display (NODE *node)
{
    if (node->type == N_OP) {
	if (node->left) {
	    if (PRECEDENCE(node, node->left)) {
		printf("(");
	    }
	    tree_display(node->left);
	    if (PRECEDENCE(node, node->left)) {
		printf(")");
	    }
	    printf(" %c ", node->val.ch);
	} else {
	    printf("%c", node->val.ch);
	}
	if (PRECEDENCE(node, node->right)) {
	    printf("(");
	}
	tree_display(node->right);
	if (PRECEDENCE(node, node->right)) {
	    printf(")");
	}
    } else {
	printf("%s", node->val.name);
    }
}
Exemple #3
0
/*
 * name: 	tree_display
 * @param:	root of the tree
 * @return:	void, just print; used for debugging
 */
void tree_display(struct tnode* head) {
    if (head->isleaf) {
        printf("(%c,%f) ",head->symbol,head->freq);
        return;
    }
    tree_display(head->right);
    tree_display(head->left);
}
Exemple #4
0
void tree_display(TreeNode_t *t)
{
    if (t != NULL)
    {
        tree_display((TreeNode_t*)t->left);
        printf("%d [%d]; ", t->data, ++level);
        tree_display((TreeNode_t*)t->right);
    }
    else
        printf("- [%d]; ", ++level);

    --level;
}
Exemple #5
0
void	tree_display(t_tree *root)
{
  if (root == NULL)
    return ;
  printf("---TREE---\n");
  printf("%s\n", root->commande_ptr->instruction);
  if (root->left)
    {
      printf("left\n");
      tree_display(root->left);
    }
  if (root->right)
    {
      printf("right\n");
      tree_display(root->right);
    }
  printf("depop\n");
}
Exemple #6
0
void tree_display(struct TreeNode* p, int level, FILE * fout)
{
	int i;
	for (i = 0; i < level * 2; i++) 
	{
		fprintf(fout, " ");
		printf(" ");
	}
	fprintf(fout, "%s [%d]", p->type_name, p->reduce_type);
	printf("%s [%d]", p->type_name, p->reduce_type);
	
	/* otherwise, maybe we should have some details! */
	if (p->type == NT_ID) 
	{
		fprintf(fout, ": %s\n", p->val.val_str);
		printf(": %s\n", p->val.val_str);
	}
	else if (p->type == NT_INT)
	{
		fprintf(fout, ": %d\n", p->val.val_int);
		printf(": %d\n", p->val.val_int);
	}
	else if (p->type == NT_TYPE)
	{
		fprintf(fout, ": %s\n", p->val.val_str);
		printf(": %s\n", p->val.val_str);
	}
	else
	{
		fprintf(fout, "\n");
		printf("\n");
	}

	if (p->child != NULL)
	{
		tree_display(p->child, level + 1, fout);
	}
	/* print siblings! */
	if (p->sibling != NULL)
		tree_display(p->sibling, level, fout);
}