how to create a tree of object

This is a discussion on how to create a tree of object within the C++ Programming forums, part of the General Programming Boards category; There are three classes which name Plus, Mult and Constant. How can i make in such a way that the ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    41

    how to create a tree of object

    There are three classes which name Plus, Mult and Constant. How can i make in such a way that the Mult class has a method that holds the 5 and 4 object which is created earlier and the Plus class has a method that holds the 3 object and also Mult object which is holding the 5 and 4 object ?? This means that the higher hierarchy the tree is, the more object the method will be holding. I would like to know if it is possible for me to find online tutorial regarding such cases. Thanks

    Code:
    Constant x = new Constant(3);
    Constant y = new Constant(5);
    Constant z = new Constant(4);
    
    3+5*4
    
             +
          |-----|
         3      *
               |----|
              5    4
    Last edited by winsonlee; 08-24-2004 at 11:01 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Each operator points to two other objects - either a constant, or another operator

    So an object containing operator + would point to a '3' and a '*'
    The '*' in turn would point to a '5' and a '4'
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BST delete again, but this time I think I'm close
    By tms43 in forum C++ Programming
    Replies: 9
    Last Post: 11-05-2006, 05:24 PM
  2. Is there anyway to create a 24-bit object?
    By maxhavoc in forum C++ Programming
    Replies: 10
    Last Post: 06-15-2006, 07:28 AM
  3. binary tree token problem
    By OldSchool in forum C++ Programming
    Replies: 13
    Last Post: 05-28-2006, 10:42 PM
  4. Tree traversal
    By recluse in forum C Programming
    Replies: 4
    Last Post: 12-05-2004, 03:00 PM
  5. Tree Problem
    By recluse in forum C Programming
    Replies: 36
    Last Post: 12-04-2004, 02:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21