Example #1
0
void inorder_traversal(struct node *root) {
    if(root != NULL) {
	inorder_traversal(root->left);
	printf("%c\t", root->data);
	inorder_traversal(root->right);
    }
}
Example #2
0
void inorder_traversal(struct node* node){
    if(node!=NULL){
    inorder_traversal(node->left);
    printf("%d ",node->data);
    inorder_traversal(node->right);
    }
}
Example #3
0
int main()
{
    root=NULL;
    int ch,k,n;
    do
    {
        printf("1:Insertion 2:Traversing 3:Searching \n");
        printf("Enter your choice\n");
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:create();
            inorder_traversal(root);
            break;
            case 2:inorder_traversal(root);
            break;
            case 3:printf("Enter the item to search\n");
            scanf("%d",&n);
                searching(root,n);
            break;
            default:printf("Wrong choice!\n");
        }
        printf("\nWant to continue type 1\n");
        scanf("%d",&k);
    }while(k==1);
    return 0;
}
void inorder_traversal(treenode *T){
	if(T==NULL)
		return;
	inorder_traversal(T->lc);
	printf("%d ", T->id);
	inorder_traversal(T->rc);
}
Example #5
0
File: main.c Project: bcho/homework
int main()
{
    char _[] = "deadbeef";
    tree_t t = create_tree(_, strlen(_));

    inorder_traversal(t, print_node);
    sep;
    printf("%c %c %c", retrieve(find_min(t)), retrieve(find_max(t)),
                       retrieve(find('a', t)));
    sep;

    t = insert_tree('z', t);
    printf("%c %c %c", retrieve(find_min(t)), retrieve(find_max(t)),
                       retrieve(find('a', t)));
    sep;
    inorder_traversal(t, print_node);
    sep;
    
    delete_tree('z', t);
    printf("%c %c %c", retrieve(find_min(t)), retrieve(find_max(t)),
                       retrieve(find('a', t)));
    sep;
    inorder_traversal(t, print_node);

    dispose_tree(t);

    return 0;
}
void inorder_traversal(BTree *T)
{   
    if(T != NULL){
        inorder_traversal(T->left);
        printf("%4d", T->data);
        inorder_traversal(T->right);
    }
}
Example #7
0
// Function for inorder traversal of Binary Tree
void inorder_traversal(struct node* tree)
{
    if(tree == NULL)
        return;
    inorder_traversal(tree->left);
    printf("\t%d", tree->data);
    inorder_traversal(tree->right);
}
void inorder_traversal(struct node *root, int *sum)
{
	if (root != NULL)
	{
		inorder_traversal(root->left, sum);
		(*sum) =(*sum)+ root->data;     
		inorder_traversal(root->right, sum);
	}
}
Example #9
0
File: 6.c Project: kgpavan/Master
void inorder_traversal( tree *T )
{
     if(T!=NULL)
     {
                inorder_traversal( T->left );
                printf("%d ",T->item);
                inorder_traversal( T->right );
     }               
}
 void inorder_traversal(TreeNode *node, vector<int>& vals) {
     if (node == NULL) {
         return;
     }
     inorder_traversal(node -> left, vals);
     vals.push_back(node -> val);
     inorder_traversal(node -> right, vals);
     return;
 }
Example #11
0
void inorder_traversal(minHeap *hp, int i) {
    if((2i) < hp->size) {
        inorder_traversal(hp, (2i)) ;
    }
    printf("%d ", hp->elem[i].data) ;
    if((2i+1) < hp->size) {
        inorder_traversal(hp, (2i+1)) ;
    }
}
Example #12
0
void
inorder_traversal(my_bs_tree t) {
    if (t == NULL) {
        return;
    }

    inorder_traversal(t->left);
    printf("%d ", t->x);
    inorder_traversal(t->right);
}
void inorder_traversal(struct node *root, int *arr, int* i1)
{
	if (root != NULL && arr != NULL)
	{
		inorder_traversal(root->left, arr, i1);
		arr[*i1] = root->data;
		(*i1)++;
		inorder_traversal(root->right, arr, i1);
	}
}
void inorder_traversal(struct node *root, int *arr, int *index){
	
	if (root == NULL)
		return;

	inorder_traversal(root->left, arr, index);
	arr[*index] = root->data;
	*index = *index + 1;
	inorder_traversal(root->right, arr, index);
}
void inorder_traversal(struct node *nroot)
{
	if(nroot != NULL)
	{
		inorder_traversal(nroot -> left);
		std::cout << nroot -> value << ",";
		inorder_traversal(nroot -> right);
	}
	return;
}
Example #16
0
void inorder_traversal(struct TreeNode *root, int **buf, int depth, int *buf_size, int *max_depth) {
    if (root == NULL) return;
    if (depth > *buf_size) {
        *buf_size <<= 1;
        *buf = (int *)realloc(*buf, sizeof(int) * (*buf_size));
    }
    if (depth > *max_depth) *max_depth = depth;

    if (root->left != NULL) inorder_traversal(root->left, buf, depth + 1, buf_size, max_depth);
    (*buf)[depth - 1] = root->val;
    if (root->right != NULL) inorder_traversal(root->right, buf, depth + 1, buf_size, max_depth);
}
Example #17
0
void inorder_traversal(struct node* temp)
{
    if(temp==NULL)
    {
        return ;
    }
    else
    {
        inorder_traversal(temp->left);
        printf("%d ",temp->info);
        inorder_traversal(temp->right);
    }
}
Example #18
0
void inorder_traversal(TLDNode *inorder[], long *curIndex, long size, TLDNode *node)
{
    if (hasLeft(node))
    {
        inorder_traversal(inorder, curIndex, size, node->left);
    }
    inorder[*curIndex] = node;
    (*curIndex)++;
    if (hasRight(node))
    {
        inorder_traversal(inorder, curIndex, size, node->right);
    }
}
string CBinarySearchDictionary::inorder_traversal(Node *pNode)
{
	string strValue = "";
	string strLeft = "";
	string strRight = "";

	if (pNode != NULL)
	{
		strLeft = inorder_traversal(pNode->pLeft);
		strRight = inorder_traversal(pNode->pRight);

		strValue = strLeft + "\t" + pNode->strNameValue + "\t" + strRight;
	}

	return strValue;
}
Example #20
0
/* word frequency count */
int main() {
	struct tnode *root, *freqroot;
	char word[MAXWORD];
	char *key[MAXKEYLIST]={NULL,};
	root = NULL;
	freqroot = NULL; // 새로운 트리를 위한 뿌리 노드를 만들어야 한다.
	while (getword(word, MAXWORD) != EOF)
		if (isalpha(word[0]))
			root = addtree(root, word);
	freqroot = createtreefromtree(root, freqroot);
	 treeprint(root);
     printf("==END::raw tree==\n");
	treeprint2(freqroot);
    printf("==END::freq tree==\n");
	inorder_traversal(root,key);
	int ti=0;
	while(key[ti]!=NULL){
        //if(ti<10){
		root=reducetree(root,key[ti++]);
        //}
		//printf("%s\n",key[ti++]);
	}
	//printf("end key list\n");
	treeprint(root);
	printf("finish print\n");
	return 0;
}
// driver program to test indenticalTrees function
int main()
{

struct node * root = newNode(1);

//root->left = newNode(2);
root->right = newNode(2);
//root->left->left = newNode(4);
//root->left->right = newNode(5);
root->right->left = newNode(3);
root->right->right = newNode(4);
root->right->left->left = newNode(8);
root->right->left->left->right = newNode(9);
root->right->left->left->left = newNode(5);
root->right->right->right = newNode(6);
//printf("preorder traversal of tree\n");
//preorder_traversal(root);
//printf("postrder traversal of tree\n");
//postorder_traversal(root);
printf("inorder traversal of tree\n");
inorder_traversal(root);
//printf("level order traversal\n");
//levelorder_traversal(root);

return 0;

}
Example #22
0
File: 6.c Project: kgpavan/Master
main()
{
	tree *t;
	t=NULL;
	int i,q,w,flag;
	char c,d;
	while(1)
	{
		scanf("%d",&q);
		c=getchar();
	//	insert(q,&t1);
		if(c=='\n')
			break;
	}
	while(1)
	{
		scanf("%d",&w);
		d=getchar();
		insert(w,&t);
		if(d=='\n')
			break;
	}
	inorder_traversal(t);
	printf("\n");
	preorder_traversal(t);
	printf("\n");
	postorder_traversal(t);
	printf("\n");
	levelprint(t);
	printf("\n");
}
Example #23
0
void dump_sorted_list(const char * filename) {
    FILE * fp = fopen(filename, "w");
    if (fp != NULL) {
        inorder_traversal(ptreeroot, fp);
        fclose(fp);
    }
}
Example #24
0
int* rightSideView(struct TreeNode* root, int* returnSize) {
    int buf_size = 1024;
    int *buf = (int *)malloc(sizeof(int) * buf_size);
    *returnSize = 0;

    inorder_traversal(root, &buf, 1, &buf_size, returnSize);
    return buf;
}
int get_missing_value(struct node *root,int n){
	if (root==NULL || n<=0)
	return -1;
	int sum = 0;
	inorder_traversal(root, &sum);
	int res =((n)*(n+1)/2) - sum;
	return res;
}
Example #26
0
static void inorder_traversal(opal_rb_tree_t *tree, 
                              opal_rb_tree_condition_fn_t cond,
                              opal_rb_tree_action_fn_t action,
                              opal_rb_tree_node_t * node)
{
    if (node == tree->nill) {
        return;
    }

    inorder_traversal(tree, cond, action, node->left);

    if (cond(node->value)) {
        action(node->key, node->value);
    }

    inorder_traversal(tree, cond, action, node->right);
}
void inorder(struct node *root, int *arr){

	if (arr == NULL)
		return;
	
	int i = 0;
	inorder_traversal( root, arr, &i);
	
}
Example #28
0
void inorder_traversal(struct tnode *p, char *key[]){
	if(p!=NULL){
		inorder_traversal(p->left,key);
		int index;
        if(p->count>0){
            char* tmp_std =mystrdup( p->word);
	        for (index = 0;
		        key[index]!=NULL&& index < MAXKEYLIST ;
		        index++) {
		            if(strcmp(key[index],p->word)>0) {
			            char* tmp =key[index];
			            key[index] = tmp_std;
			            tmp_std = tmp;
		            }
	            }
	        key[index]=tmp_std;
        }
		inorder_traversal(p->right,key);
	}
}
Example #29
0
int main(int argc, char **argv){
	srand(time(NULL));
	tree_node *root = (tree_node *)malloc(sizeof(tree_node));
	root->data = 0;//rand()%10;
	makeTree(root);
	printf("PreOrder:");
	printPreOrder(root);
	printf("\n");

	printf("Inorder traversal: ");
	inorder_traversal(root);
	printf("\n");
/*	printf("Max in tree = %d\n",find_max(root));
	printf("Reverse Level Order :");
	printReverseLevelOrder(root);
	printf("Height of tree = %d\n",height_of_tree(root));
*/
	tree_node *root1 = root;
	tree_node *root2 = (tree_node *)malloc(sizeof(tree_node));
	root2->left = root2->right = NULL;
	root2->data = 0;
	makeTree(root2);
	printf("Are they structurally identical = %d\n",isStructurallyIdentical(root1, root2));

	tree_node *root3 = (tree_node *)malloc(sizeof(tree_node));
	root3->left = root3->right = NULL;
	MakeAMirror(root1, root3);

	printf("Inorder traversal of Mirrored Tree :");
	inorder_traversal(root3);
	printf("\n");

	printf("Diameter of tree = %d\n", diameterOfTree(root1));
	printAllPathsToLeaf(root1);

	DeleteTree(root1);
	DeleteTree(root2);
	DeleteTree(root3);

	return 0;
}
Example #30
0
int opal_rb_tree_traverse(opal_rb_tree_t *tree,
                          opal_rb_tree_condition_fn_t cond,
                          opal_rb_tree_action_fn_t action)
{
    if ((cond == NULL) || (action == NULL)) {
        return OPAL_ERROR;
    }

    inorder_traversal(tree, cond, action, tree->root_ptr->left);

    return OPAL_SUCCESS;
}