Thread: what this function does..(i tried to trace it)

  1. #16
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    what commands in this code are changing the structure of the tree?
    lines like this:
    Code:
    save=save->lc;
    only changes our perspective on the tree
    this line only makes us look on a different section of a tree
    Last edited by transgalactic2; 10-29-2008 at 07:49 AM.

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by tabstop View Post
    I don't know what the algorithm is supposed to do for sure -- I know what it is close to doing, but it is not doing so. (That is to say, left and right are not being treated symmetrically, possible segfaults are being created, and so on.) Part of that, apparently, is that temp is just ... there ... and not being used. You're right that what's there is probably not wanted, but who knows what it's supposed to be.
    The variable temp is being used at the very end of the function.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    what commands change the structure of a tree?
    Last edited by transgalactic2; 10-29-2008 at 03:59 AM.

  4. #19
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    A tree is changed by adding or deleting a node.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #20
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i got this example
    look how this function change it
    and in this code there is no adding or deleting nodes

    so i am wondering from where these changes came from?

    http://img397.imageshack.us/my.php?i...2032860fw8.gif
    Last edited by transgalactic2; 10-29-2008 at 04:21 AM.

  6. #21
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by transgalactic2 View Post
    i got this example
    look how this function change it
    and in this code there is no adding or deleting nodes

    so i am wondering from where these changes came from?

    http://img397.imageshack.us/my.php?i...2032860fw8.gif
    That picture shows a deletion of the root node and a subsequent re-balancing of the tree.
    So, yeah, there is a deleting of a node.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  7. #22
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    but in this code i only see references stuff
    o addition or deletion

  8. #23
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You CHANGE the structure of a BST by changing what the left and right nodes point to. In this case, there are a few lines where lc or rc is set to point at a different node.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #24
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by matsp View Post
    The variable temp is being used at the very end of the function.

    --
    Mats
    Oh right right, 'cause temp is tree. Right. Sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM