Binary Search Tree Insertion Algorithm Help

This is a discussion on Binary Search Tree Insertion Algorithm Help within the C++ Programming forums, part of the General Programming Boards category; I have looked high and low on the web for the insertion algorithm for a BST. Can anyone either point ...

  1. #1
    Shake Zula- The Mic Rula!
    Join Date
    Sep 2004
    Posts
    69

    Binary Search Tree Insertion Algorithm Help

    I have looked high and low on the web for the insertion algorithm for a BST. Can anyone either point me in the right direction or provide one for me. Thanks!!

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    1) compare new node vs. root node

    2) LOOP: if less, return node->left. if greater, return node->right.
    Test for a terminating case w/ each iteration.

    3) Now you have a pointer to where the node is supposed to be inserted.
    Make the proper pointer assignments to make the insertion.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Shake Zula- The Mic Rula!
    Join Date
    Sep 2004
    Posts
    69
    how do i initalize the first node, use a constructer in my node declaration to set the pointers *left and *right to NULL, then in my gooey of the "insertNode" alg, do i set "node Newnode = new node"?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple binary search tree?
    By sybariticak47 in forum C++ Programming
    Replies: 8
    Last Post: 08-09-2007, 04:53 PM
  2. Binary search needed
    By ItsMeHere in forum C Programming
    Replies: 1
    Last Post: 06-22-2006, 08:26 AM
  3. Inserting words into a binary search tree
    By lime in forum C Programming
    Replies: 9
    Last Post: 08-02-2003, 11:02 PM
  4. Ornery binary search algorithm
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-17-2001, 03:32 PM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21