On Wed, 2004-09-22 at 07:24, Paul Akkermans wrote:
> Hi group,
>
> I have constructed the following code:
> struct node
> { TreeElementType elt;
> struct node *left, *right;
> };
> typedef struct node Node;
>
> typedef Node *Tree;
>
> #include <stdio.h>
> #include "tree.h"
>
> void WriteTreeSlave( Tree T, int indent ) /*L.Allison*/
> /* Write a tree, with root at the LHS, by a right-to-left, infix traversal */
> { int i; char str[]="----------|";
>
> if( T != NULL )
> { WriteTreeSlave(T->right, indent+1);
>
> for(i=0; i < indent; i++) printf(" |");
> sprintf(str, "%s", T->elt); /* NB. assumed to be a Tree of String */
> i = 0;
> while( str[i] != NULL ) i++;
> while( i < 10 ) { str[i]='-'; i++; }
> str[i] = '|'; str[i+1] = NULL;
> printf("%s\n", str);
>
> WriteTreeSlave(T->left, indent+1);
> }
> }/*WriteTreeSlave*/
>
> void WriteTree( Tree T ) { WriteTreeSlave(T, 0); }
>
> /* Write a Tree down the page. */
>
> int main (){
> WriteTreeSlave("paul",0);
>
> It is my goal to call the function "WriteTreeSlave(?,?)" but I don't
> know what variables I have to give along with this function (that's
> why I placed the ?-mark there) . Ik have tried ("paul",0); but that
> doesn´t work. Can anybody help me?
>
Behind all the convoluted typedefs, WriteTreeSlave() takes a node (at
least that's how it's prototyped). You are passing a string literal and
never even declare a node.
In fact WriteTreeSlave() makes a recursive call back to itself and
clearly (or rather not so clearly due to the typedefs) passes a node
object as the first arg (T->left) as an inorder binary tree traversal
usually does.
This looks like ugly code from some textbook.
--
Eric Gaumer <gaumerel@ecs.fullerton.edu>
Attachment:
signature.asc
Description: This is a digitally signed message part