guys how u do this on C
many thanks for ur help...... :-)Code:sample input: a=b+c*d ouput: = / \ a + / \ b * / \ c d
guys how u do this on C
many thanks for ur help...... :-)Code:sample input: a=b+c*d ouput: = / \ a + / \ b * / \ c d
yup somewhat like it...i hope you could help me with this..
For a binary tree you need a structure like this
and the rest is just applying linked list theory. When having to implement a thing like you want, I guess you know about linked lists.Code:struct node_s { int data; struct node_s *left_child; struct node_s *right_child; };
there's a program i got a while ago from snippets.org, it does the same thing(evaluate an expression).
Provided you've already build the tree you can print it out fairly easily.
-PreludeCode:void printNode( char c, int h ) { int i; for( i = 0; i < h; ++i ) printf( " " ); printf( "%c\n", c ); } void show( struct node *x, int h ) { if( x == NULL ) { printNode( '*' , h ); return; show( x->right, h + 1 ); printNode( x->data, h ); show( x->left, h + 1 ); }
My best code is written with the delete key.
what he means is this
a=((c*d)+b)
Spacing is the only important thing needed when the tree is finished. Use field widths.
Like vasanth said, I think he was after the expression not a binary tree.
Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)