🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.borland
Article #640

Re: Binary-Tree

#640
From: Timothy Groner
Date: Fri, 15 Mar 1996 00:00
29 lines
1920 bytes
In <4hvfiu$h0v$1@mhadf.production.compuserve.com> Neil Ford <100717.3246@CompuServe.COM> writes:

>Hello,

>Can anyone help with a program which is required to remove a node 
>from a binary tree while maintaining its integrity.

I'm assuming you mean a plain binary tree.

There are three cases to consider.  
Case 1:  The node you want to delete has no children.
  Solution is trivial.
Case 2:  The node you want to delete has one child.
  Solution:  Remove the node and attach the child to the deleted node's 
parent, not necessarily in that order.
Case 3:  Node has two children.
  Solution:  Turn it into a Case1  or Case 2 situation by using a method 
called the Inorder Successor Method.  Swap the **contents** (in this case 
a pointer to a linked list), with the contents of the node's inorder 
successor (the next highest value).  The inorder successor can never have 
more than one child, leaving you with a Case 1 or Case 2 situation.  The 
inorder successor is physically located to the right one node and down as 
far left as you can go.

-- 

  Tim Groner
  e-mail: Tim_Groner@Umanitoba.ca
  http://home.cc.umanitoba.ca/~umgroner        
Technical Details
Message-ID: <umgroner.826914773@merak>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <4hvfiu$h0v$1@mhadf.production.compuserve.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10261c,2b24ce677e1115df,start
X-Google-Attributes: gid10261c,public
X-Google-Thread: f461d,2b24ce677e1115df,start
X-Google-Attributes: gidf461d,public
X-Google-Thread: 111659,e32d93a5a0efee55
X-Google-Attributes: gid111659,public
X-Google-Thread: 102601,2b24ce677e1115df,start
X-Google-Attributes: gid102601,public
From: umgroner@cc.umanitoba.ca (Timothy Groner)
Subject: Re: Binary-Tree
Date: 1996/03/15
Message-ID: <umgroner.826914773@merak>
X-Deja-AN: 142800726
references: <4hvfiu$h0v$1@mhadf.production.compuserve.com>
organization: The University of Manitoba
newsgroups: comp.lang.pascal.borland,comp.lang.pascal.misc,ctdl.lang.pascal,relcom.comp.lang.pascal