Re: [Dev-C++] Printing of an expression tree
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2007-02-23 09:27:54
|
For an expression to be meaningful (emitted in pre-order, in-order,
post-order) you must of course always emit _all parts_ of the expression.
Hence, you don't have to worry about 'which' part to emit. You must emit
both parts. If one half of the tree is NULL, then you must print it anyway
- either as a space-filling intendation, or as a NULL message or whatever.
Exactly how you print it, is part of what the assignment wants _you_ do
decide/solve. How do you know when you have solved the exercise correctly?
When you can read the printout, and clearly see - and restore - the
original expression from your printout.
But once more: how to do it is _your_ job, and shouldn't be solved by
cooperation on mailing lists. You know very well that it is considered
cheating - and a lot of schools can (and will) punish students for using
mailing lists.
/Per W
On Fri, 23 Feb 2007, Jonathan Winterflood wrote:
> Hi,
>
> Well it'd depend on how your tree was builtr.
> The way I did it (in a compilation assignment) was that the since the treee
> was hierarchical, print (left op right)
>
> eg 1+5*6/7+8 is ((1+((5*6)/8))+8) would decompose to this tree
>
>
> | root:,
> a , + 8
> b 1 + ,
> c , / 7
> d 5 * 6
> |
>
> so print a prints ( printb + 8)
>
>
>
> +
> On 2/23/07, Noorez Kassam <lor...@ho...> wrote:
> >
> > I'm having a bit of trouble with an assignment I need to do for recursion
> > and binary trees. I need to print an arithmetic expression tree. The struct
> > must be defined as follows:
> >
> > struct TreeNode
> > {
> > char op;
> > int number;
> > TreePtr left;
> > TreePtr right;
> > };
> >
> >
> > void in_order_print(TreePtr tree)
> > {
> > TreePtr currentNode = tree;
> > if(currentNode != NULL)
> > {
> > if(currentNode->left != NULL)
> > {
> > in_order_print(currentNode->left);
> > }
> > // print which data?
> > if(currentNode->right != NULL)
> > {
> > in_order_print(currentNode->right);
> > }
> > }
> > }
> >
> > Since there are two fields which contain data, how would I know in the
> > recursive algorithm which one to print?
> >
> > ------------------------------
> > Explore the seven wonders of the world Learn more!<http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE>
> >
> > -------------------------------------------------------------------------
> > Take Surveys. Earn Cash. Influence the Future of IT
> > Join SourceForge.net's Techsay panel and you'll get the chance to share
> > your
> > opinions on IT & business topics through brief surveys-and earn cash
> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
> >
>
>
> --
> <Morpheus> linux, c'est une question de VI ou de MORE
>
|