need help on TREE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • enjoyincubus
    New Member
    • Jun 2006
    • 10

    need help on TREE

    Hi there

    can you guys help me?

    i know theres a function insert and findMin or findMax in TREE

    but what about delete?

    how do you write the code using TREE in a linked - list implemintation?


    help is greatly appreciated.
  • enjoyincubus
    New Member
    • Jun 2006
    • 10

    #2
    anyone please?

    Comment

    • smartway
      New Member
      • Oct 2006
      • 24

      #3
      Which tree you are using ?

      Comment

      • enjoyincubus
        New Member
        • Jun 2006
        • 10

        #4
        Originally posted by smartway
        Which tree you are using ?

        binary search tree

        can you help me?


        dont know the code

        Comment

        • D_C
          Contributor
          • Jun 2006
          • 293

          #5
          They have an algorithm for BST delete implemented here in C++.

          Comment

          • enjoyincubus
            New Member
            • Jun 2006
            • 10

            #6
            Originally posted by D_C
            They have an algorithm for BST delete implemented here in C++.
            thanks man!

            Comment

            • enjoyincubus
              New Member
              • Jun 2006
              • 10

              #7
              i have read and understand some of the code


              but i still have some questions


              what does "def" mean?


              and is there a C implemintation for the function "search" since i dont quite understand python.

              Comment

              • D_C
                Contributor
                • Jun 2006
                • 293

                #8
                I assume def is shorthand for "define", it's like declaring the function. I'll change things into more of C like code. I do C++ instead of C, and have not tested this, so it may not be 100% correct. That's not such a bad thing, because you'll still have to understand it to fix it :).
                Code:
                *Node search_binary_tree(Node *n, int key) // key type is arbitrary
                {
                    if(n == null)    // we traversed past a leaf
                        return null; // the key does not exist in a node
                
                    if(key < n->key) // if the key is less than this node
                                     // recursively the left node
                        return search_binary_tree(n->left, key) 
                
                    else if(key > n->key) // if the key is greater than this node
                                          // recursively search the right node
                        return search_binary_tree(n->right, key) node
                
                    else          // otherwise the key is equal to this node's key
                        return n; // we found it, so return a pointer to it.
                }

                Comment

                Working...