/* ECP: FILEname=fig11_17.c */ /* 1*/ Tree /* 2*/ Insert( Tree Root, const char *X ) /* 3*/ { /* 4*/ int Cmp; /* 5*/ if( Root == NULL ) /* Spot Found */ /* 6*/ { /* 7*/ Root = malloc( sizeof( struct TreeNode ) ); /* 8*/ if( Root == NULL || ! ( Root->Item = Strdup( X ) ) ) /* 9*/ Error( "Out of space!!" ); /*10*/ Root->Count = 1; /*11*/ Root->Left = Root->Right = NULL; /*12*/ } /*13*/ else /* X < Root->Item */ /*14*/ if( ( Cmp = strcmp( X, Root->Item ) ) < 0 ) /*15*/ Root->Left = Insert( Root->Left, X ); /*16*/ else /*17*/ if( Cmp > 0 ) /* X > Root->Item */ /*18*/ Root->Right = Insert( Root->Right, X ); /*19*/ else /*20*/ Root->Count++; /* X Was Previously Seen */ /*21*/ return Root; /*22*/ }