Thread: need help badly...

  1. #1
    Unregistered
    Guest

    Unhappy need help badly...

    guys how u do this on C
    Code:
    sample input: a=b+c*d
    ouput:
                   =
                  /  \
                a    +
                     /  \
                    b    *
                         /  \ 
                        c     d
    many thanks for ur help...... :-)

  2. #2
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Is that a binary tree or somethin?

  3. #3
    Unregistered
    Guest

    Smile

    yup somewhat like it...i hope you could help me with this..

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    For a binary tree you need a structure like this

    Code:
    struct node_s
    {
        int data;
        struct node_s *left_child;
        struct node_s *right_child;
    };
    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.

  5. #5
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    there's a program i got a while ago from snippets.org, it does the same thing(evaluate an expression).

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Provided you've already build the tree you can print it out fairly easily.
    Code:
    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 );
    }
    -Prelude
    My best code is written with the delete key.

  7. #7
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    what he means is this


    a=((c*d)+b)

  8. #8
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Spacing is the only important thing needed when the tree is finished. Use field widths.

  9. #9
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    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)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is my loop badly set up?
    By mabufo in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2006, 03:40 PM
  2. need help, badly
    By VivisectErasmus in forum C Programming
    Replies: 2
    Last Post: 05-22-2005, 06:15 AM
  3. char arrays, pointers, etc, could use help badly
    By Nakeerb in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2002, 10:20 PM
  4. Newbie needs C++ help with pauses- help needed badly.
    By dgprog in forum C++ Programming
    Replies: 2
    Last Post: 07-11-2002, 05:11 PM
  5. need some advice...badly.
    By heavyd in forum C++ Programming
    Replies: 1
    Last Post: 12-12-2001, 04:49 AM