Thread: strange return value

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    6

    strange return value

    I'm writing a binary tree and having some problems. In my delete method, I return 1 if the root is the only node in the tree and it is deleted and a 0 in every other case. When I run the program, for some reason in a certain case, I get the value of 163920. Here's the code for that case:
    Code:
    if(right == NULL && left == NULL)
    {
      BTN *t = this;
       if(parent == NULL)
       {
        delete t;
        return 1;
       }
       /*int lorr = parent->lorr(name);
       if(lorr == 1)
       {
        parent->left = NULL;
        //parent = NULL;
        delete t;
       }
       else
       {
        parent->right = NULL;
        //parent = NULL;
        delete t;
       }*/
       delete t;
       return 0;
    }
    The node I'm trying to delete ought to return 0. Does having that "delete t;" mess with the return? Any help is greatly appreciated.

    Tagged by Salem - next time, read http://cboard.cprogramming.com/misc....bbcode#buttons

  2. #2
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I've heard about compiler problems with returning a value that isn't in parenthesis, so you may wish to use them, as so:

    return(1);
    return(0);

    just to ensure that it is compiling properly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  2. sort linked list using BST
    By Micko in forum C Programming
    Replies: 8
    Last Post: 10-04-2004, 02:04 PM
  3. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM
  5. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM