Thread: how to create a tree of object

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

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, 06: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, 04:00 PM
  5. Tree Problem
    By recluse in forum C Programming
    Replies: 36
    Last Post: 12-04-2004, 03:06 PM