![]() |
|
#1
|
||||
|
||||
Deleting node - binary search treeHello folks.
been trying to delete a node from a binary search tree (sorted tree that is). The delete does not work as expected. Heres the code: CPP / C++ / C Code:
If given the following input to insert node: 13 5 14 10 9, 13 becomes the root, with 5 on its left and 14 on its right. Again 10 goes to the right of 5 and then 9 goes to the left of the newly inserted 10. Thus an inorder traversal after this shows 9 13 14 and theres no mention of 10. When im trying to remove 5, it does the right thing by replacing 5 with 9 (the smallest element in the right i.e. 'greater than' sub tree), but it also removes the intermediate 10 (which precedes 9). I do not understand where in this world am I erring Again when I use free inside a function, as I am using now, I make the target memory location available for writes if im right? Any input or suggestings would be high appreciated. __________________
Hope to hear from you guys! -------------------------------------------------- Best Regards, Aijaz Baig. |
||||
|
#2
|
|||
|
|||
Re: Deleting node - binary search treeWhen I run your program with that input I get the following:
Quote:
Quote:
CPP / C++ / C Code:
CPP / C++ / C Code:
__________________
My personal site: Utilities for text processing, debugging, testing and plotting |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Str_Misaligned in Double Link List | Peter_APIIT | C Programming Language | 1 | 29-Feb-2008 21:50 |
| Deleting a node from binary search tree | earachefl | C++ Forum | 3 | 28-Jun-2006 08:26 |
| can anyone help me with my tree :) | bioeng_mtm | C++ Forum | 5 | 22-Apr-2006 13:50 |
| Binary Search Tree | penance | C Programming Language | 2 | 07-Aug-2005 05:37 |
| Search Engine Positioning 101 and 201 "How To" Tips... | 000 | Search Engine Optimization Forum | 0 | 29-May-2003 11:34 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The