Thread: hard tree question

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    2

    hard tree question

    i've writen a program that prints a list of words to a file. it uses an avl tree for balancing.

    could some please tell me why my height function doesn't work and why the produced file doesn't have any words in it.

    thanks.

    <please see attached file>

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >if ( avl != NULL );
    This has no affect, as you've left an extra semi-colon on the end by mistake.

    >main() needs a return code even if avl == NULL.

    >int max(int a, int b)
    My compiler complains about this. I guess there's already a function called max, so I suggest you rename it. Also, it needs a prototype.
    [edit] max() is in stdlib.h, and is a macro:
    Code:
    #include <stdlib.h>
    #define max(a,b)  (((a) > (b)) ? (a) : (b))
    [/edit]
    >tolower()
    you do realise this only does one character?
    Last edited by Hammer; 05-22-2002 at 03:25 AM.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Also, you're not storing the pointer of the list:
    >insert(word, avl);
    You'll need to store it, something like this (depending on how your insert function is working).
    >avl = insert(word, avl);

    It still doesn't work properly, but I don't have time to help out at present.... <sorry>
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    2

    Smile

    thanks hammer.
    i've made those corrections. its now printing to the file - but only the the last word several times - hey, were getting there!! ta.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Tree Search
    By C++Newbie in forum C++ Programming
    Replies: 7
    Last Post: 04-05-2011, 01:17 AM
  2. 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
  3. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  5. Help: One Question for each: Linked List and Tree
    By Yin in forum C++ Programming
    Replies: 1
    Last Post: 04-14-2002, 12:57 AM