binary search tree
binary search tree
Binay whon
2
maul
Bina Seach roe is a binaau
Eree in which fon venol x in t h
20
Node deelaation
Struct Trouodu
tret aue
Make empty
2 T n s e t i o n
3 Delution
4 Pind
5 Find min
6. Pind max
f (T!NOLL)
Tetum NOL
Find
This opeation oiu fird ky x in
kug value
Purahi
ram
on
Position Pind (Element Type x, SeaaCh lrat)
raT)
If CT== JoLL
9 otun NOLC)
if CxeT-> Element)
Tetun Fird Cx, T->Lutt)D
ese
if Cx>T>Elemant)
retum Pind Cx T Pght);
ele
retun T;+ tey founo
3
Pid Min
This routine Tetun th Position of
Smalleyt elumant in the tro
To Potom a Find min, Staut at
tha reot ad go Jat a dong ay thure
is a dlt child
Th stoPping point 's thuior
Smallyt Oumint
9
if CT= =NULL) o
Toturn NOLC
else
if CT-> Jtt == NULL)
return T
ese
Totum ind Min CT7t);
Find Max
fCT = NUL)
Tetun NOLL
eLe
If (Trght== NULL)
otun T
oe
retun Ptnd Max (7-> Right)
Inseuti on '
To Inse x intoEree T, PooCeed
th Find furction
inseut 8
inseut 6no oneq
inseut 5
13
tnset 13 nsaut I
odolbG 18
13
Seauch lree
SeCuch Tre T)
n set Element Type I,
if CT= =NOLL)
Trowode)):
= maulloc size ot (strowt
if CT== uOLL)
Space D b
Fatal EnoY o u t of
olse
T SElement =X
T- t = NUL;
1 - Pight -
NOLL
3
ele
if CxT Element)
TRight Inseut XT-> RighE); 9 0
if CxeT> Element
T-Left = Inseut Cx,T > Let);
return TT
Delution
node o ith no children
Case 1 Tf th node is a Au,rt can be
duluted immediakely
e
aft
dalubing
JOo T
Caxe 9 nodo wth one chtld -
To dulute
Frtte
duut
4
d
ngmolsTA)
CUse 3 hode CwHh toochildren
To dulte 2 Jnom93
Roplace
the hode in place of duuted
hodu
aftu
dulutig
2 (2
Position Tempell
if CT== NULL)
Exor CElement not found")
else
CxeT ElemenE)
T-Lot =Delute (x,T->lett)
ele
iF CxT Elemant)
Tetun T
Jnomo3
amo
ni bo9-
umo3
nuwmo3