2叉查找树的删除进程:
假定要删除树T中的某节点z,此时对如何删除z要分3种情况斟酌:
1. z无子女:此时直接删除z便可
//z无子女
TREE-DELETE0(T,z)
{
if(z == left[p[z]])
left[p[z]] = NULL;
else
right[p[z]] = NULL;
p[z] = NULL;
}
TREE-DELETE0(T,z)
{
if(z == left[p[z]])
left[p[z]] = NULL;
else
right[p[z]] = NULL;
p[z] = NULL;
}
2. z有1个子女:用其子节点代替自己便可
//z只有1个子女
TREE-DELETE1(T,z)
{
//y为z的子女
if(left[z] !=NULL)
y = left[z];
else
y = right[z];
//用y代替z并将z删除
if(z == left[p[z]])
p[y] = left[p[z]];
else
p[y] = right[p[z]];
p[z] = NULL;
}
TREE-DELETE1(T,z)
{
//y为z的子女
if(left[z] !=NULL)
y = left[z];
else
y = right[z];
//用y代替z并将z删除
if(z == left[p[z]])
p[y] = left[p[z]];
else
p[y] = right[p[z]];
p[z] = NULL;
}
3. z有两个子女:删除z的后继y(y不会有左子女,删除T中的y对应情况1或2),再用y的内容代替z的内容
//z有两个子女(这里实际上是删除y)
TREE-DELETE2(T,z)
{
y = TREE-SUCCESSOR(z);
x = right[y];
//z的后继y无子女
if(x == NULL)
TREE-DELETE0(T,y);
else
TREE-DELETE1(T,y);
key[z] = key[y];
}
TREE-DELETE2(T,z)
{
y = TREE-SUCCESSOR(z);
x = right[y];
//z的后继y无子女
if(x == NULL)
TREE-DELETE0(T,y);
else
TREE-DELETE1(T,y);
key[z] = key[y];
}
删除2叉查找树的总进程:
TREE-DELETE(T,z)
{
if(z == root[T])
{root[T] = NULL;return;}
bool bleftEmpty = (left[z] == NULL);
bool brightEmpty = (right[z] == NULL);
//左右均不为空
if(!bleftEmpty && !brightEmpty )
TREE-DELETE2(T,z);
//左右均为空
else if(bleftEmpty && brightEmpty)
TREE-DELETE0(T,z);
//只有1个子女
else
TREE-DELETE1(T,z);
}
{
if(z == root[T])
{root[T] = NULL;return;}
bool bleftEmpty = (left[z] == NULL);
bool brightEmpty = (right[z] == NULL);
//左右均不为空
if(!bleftEmpty && !brightEmpty )
TREE-DELETE2(T,z);
//左右均为空
else if(bleftEmpty && brightEmpty)
TREE-DELETE0(T,z);
//只有1个子女
else
TREE-DELETE1(T,z);
}
可简写为:
1.肯定y为要删除的节点:若z无子女则y为z;若z唯一1个子女则y为该子女;若z有两个子女则y为z的后继
if(left[z] == NULL || right[z] == NULL)
y = z;
else
y = TREE-SUCCESSOR(z);
y = z;
else
y = TREE-SUCCESSOR(z);
2.将x置为y的非空子女,若y无子女,则x置为空。若z无子女,则y为z,此时x为空;z有1个子女,y为z,此时x为z的子女;z有两个子女,y为z 的后继且由2叉查找树性质知y最多只有1个孩子,x为y的子女(可能为空)。综上,x要末为y的唯1的非空子女,要末为空。
if(left[y] != NULL)
x = left[y];
else
x = right[y];
x = left[y];
else
x = right[y];
3.通过修改p[y]和x的指针删除y。
if(x != NULL)
p[x] = p[y];
if(p[y] == NULL)
root[T] = x;
else if(y == left[p[y]])
left[p[y]] = x;
else
right[p[y]] = x;
p[x] = p[y];
if(p[y] == NULL)
root[T] = x;
else if(y == left[p[y]])
left[p[y]] = x;
else
right[p[y]] = x;
4.如果z有两个子女,则z的后继是要被删除的节点,应将y中的内容复制置z:
if(y != z)
key[z] = key[y];
key[z] = key[y];
即:
TREE-DELETE(T,z)
{
//肯定y为要删除的节点
if(left[z] == NULL || right[z] == NULL)
y = z;
else
y = TREE-SUCCESSOR(z);
if(left[y] != NULL)
x = left[y];
else
x = right[y];
if(x != NULL)
p[x] = p[y];
if(p[y] == NULL)
root[T] = x;
else if(y == left[p[y]])
left[p[y]] = x;
else
right[p[y]] = x;
if(y != z)
key[z] = key[y];
}
{
//肯定y为要删除的节点
if(left[z] == NULL || right[z] == NULL)
y = z;
else
y = TREE-SUCCESSOR(z);
if(left[y] != NULL)
x = left[y];
else
x = right[y];
if(x != NULL)
p[x] = p[y];
if(p[y] == NULL)
root[T] = x;
else if(y == left[p[y]])
left[p[y]] = x;
else
right[p[y]] = x;
if(y != z)
key[z] = key[y];
}
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » 二叉树删除详解
波比源码 » 二叉树删除详解
levofloxacin cheap order levaquin 250mg generic
purchase dutasteride sale zofran 8mg ca order zofran 4mg pill
brand aldactone valtrex buy online buy fluconazole 100mg online cheap
order ampicillin erythromycin 250mg canada erythromycin without prescription
buy fildena 50mg online cheap sildenafil 100mg usa methocarbamol usa
sildenafil 50mg sale aurogra cost purchase estrace for sale
order lamotrigine 200mg without prescription order mebendazole 100mg generic buy tretinoin
buy tadalafil 20mg online order avanafil 200mg without prescription voltaren 50mg uk
order accutane online cheap accutane 10mg tablet buy zithromax 250mg online cheap
indomethacin 75mg tablet trimox 500mg oral cheap trimox 500mg
buy tadalafil 40mg sale Buy online viagra oral sildenafil
order generic arimidex 1mg Buy pfizer viagra buy sildenafil 50mg without prescription
acheter 40mg tadalafil viagra gГ©nГ©rique sildenafil 100mg generique pas cher
cialis 10mg kaufen für männer tadalafil kaufen viagra 100mg bestellen
order isotretinoin 20mg generic accutane 40mg without prescription ivermectin 80 mg
order doxycycline 100mg online cheap oral lasix lasix 100mg price
buspar pills buy ditropan 5mg online cheap oxybutynin 5mg
olmesartan order acetazolamide order acetazolamide 250 mg cheap
prograf order order prograf 5mg sale buy urso 150mg
buy cialis 10mg online cheap viagra recommended dosage buy viagra 100mg generic
tadalafil 40mg uk order cialis 5mg pill amantadine for sale online
buy fluvoxamine 50mg pill glucotrol order online glipizide ca
accutane 40mg usa order prednisone 10mg pill buy deltasone for sale
order piracetam order nootropil 800mg pills viagra 100mg uk
purchase chloroquine online cheap aralen brand baricitinib uk
order generic glucophage glycomet online cialis order online
cheap zyprexa order zyprexa 10mg online cheap purchase valsartan generic
amlodipine tablet order viagra pills female cialis tadalafil
buy clozaril 100mg generic ipratropium 100mcg pills order decadron
buy sildenafil 50mg online cheap lisinopril 5mg ca lisinopril canada
purchase prilosec generic academicwriting casino games
buy generic metoprolol 50mg order generic tenormin 100mg levitra 10mg cheap
purchase cialis online cheap viagra pills 50mg viagra 50mg us
aristocort 4mg cost triamcinolone online buy buy clarinex 5mg generic
prices of cialis plavix ca clopidogrel 150mg uk
generic zyloprim 300mg buy rosuvastatin without prescription buy ezetimibe 10mg generic
generic cozaar 25mg topamax ca topiramate cheap
order ozobax online cheap baclofen 25mg drug toradol 10mg pill
colchicine over the counter legitimate online slots for money red dog casino
order zantac online buy celecoxib 100mg pill buy celebrex pill
free roulette games money poker online free blackjack online
buy tamsulosin 0.4mg for sale buy flomax 0.4mg without prescription spironolactone 25mg without prescription
simvastatin without prescription simvastatin online order proscar sale
metronidazole 400mg usa bactrim 960mg over the counter oral bactrim 480mg
sildenafil 50mg tablet buy cialis 5mg pill cialis overnight delivery
real poker online ocean casino online order cialis 20mg pills
academic writing article stromectol without prescription ivermectin 0.5 lotion
zithromax 500mg pills neurontin pill brand neurontin
online casinos for real money cheap provigil buy generic modafinil
brand lasix 40mg oral hydroxychloroquine 200mg hydroxychloroquine order online
purchase retin sale order avana 100mg pills avanafil 200mg pills
buy tadalafil 10mg online cheap order diclofenac 50mg for sale indomethacin cost
order terbinafine generic generic lamisil 250mg trimox brand
generic actos purchase sildenafil sale pfizer viagra
buy cialis 10mg generic Canadian pharmacy cialis pfizer play slots
oral adalat 10mg buy nifedipine 10mg fexofenadine brand
order altace generic order etoricoxib pill etoricoxib 60mg price
cheap essays online cheap essay online order azulfidine 500mg pills
mesalamine 800mg uk buy avapro 300mg without prescription buy irbesartan pills
temovate pills temovate over the counter cordarone 200mg drug
order dapoxetine 60mg online cheap avana 100mg over the counter motilium tablet
doxycycline 200mg tablet doxycycline order medrol order online
famotidine 40mg cost buy remeron 15mg without prescription mirtazapine 30mg canada
buy tadalafil sale Best price for cialis where to buy otc ed pills
accutane 20mg over the counter deltasone without prescription order ampicillin pill
oral fildena order fildena 100mg buy finasteride 5mg
purchase zofran for sale order ondansetron 8mg pill bactrim brand
prednisolone 10mg ca prednisolone 40mg uk purchase furosemide online cheap
doxycycline order online buy vardenafil without prescription buy acyclovir 400mg without prescription
order inderal diflucan for sale coreg 25mg us
generic simvastatin order generic sildalis sildenafil 100mg pills for sale
zetia 10mg pill generic sumycin 500mg methotrexate 10mg sale
order levofloxacin pill bupropion buy online order zyban 150mg pills
buy zyrtec generic zoloft where to buy buy generic sertraline over the counter
purchase cenforce generic cenforce 50mg over the counter metformin 500mg for sale
buy femara generic order femara 2.5mg for sale sildenafil sale
purchase cialis pills order cialis 10mg online buying ed pills online
buy ivermectin 6mg purchase stromectol online cheap accutane 10mg without prescription
provigil online order buy promethazine for sale where can i buy prednisone
amoxicillin 250mg brand buy cheap generic prednisolone prednisolone 20mg brand
purchase absorica generic amoxicillin over the counter zithromax 500mg drug
order neurontin 600mg pill neurontin 800mg uk generic doxycycline 100mg
buy doxycycline tablets ventolin inhalator cost buy generic clavulanate over the counter
atenolol 50mg without prescription femara 2.5mg price buy letrozole sale
order levoxyl pills buy clomid generic levitra brand
purchase albendazole pills provera 10mg drug buy medroxyprogesterone 5mg online cheap
order lisinopril 2.5mg online order metoprolol 100mg pills lopressor 50mg for sale
lyrica online order order priligy 30mg without prescription order dapoxetine pill
crestor 20mg us ezetimibe 10mg uk buy motilium 10mg sale
buy imitrex 50mg online sumatriptan sale avodart 0.5mg tablet
tamsulosin 0.4mg canada order flomax for sale buy spironolactone 25mg online cheap
buy cymbalta online cheap glucotrol 5mg drug generic nootropil 800mg
buy betnovate generic anafranil us itraconazole generic
ipratropium online buy combivent 100mcg over the counter linezolid 600 mg for sale
bystolic 5mg usa order clozapine generic buy generic clozapine 50mg
buy tegretol pills ciprofloxacin 500mg pills lincocin usa
buy tadalafil for sale order cialis 5mg for sale brand sildenafil
order duricef 250mg online cheap buy lamivudine for sale order finasteride 5mg online cheap
order estrace 2mg pills order estradiol online minipress 2mg cheap
flagyl medication septra without prescription order keflex online cheap
avanafil 100mg without prescription avana price cost diclofenac 100mg
purchase indocin online cheap suprax 200mg usa buy suprax
buy trimox 250mg generic anastrozole order biaxin without prescription
catapres 0.1 mg us buy generic spiriva 9 mcg buy tiotropium bromide 9 mcg online
where can i buy minocycline purchase actos generic actos 15mg us
tadalafil 40mg oral tadalafil 40mg pills generic for cialis
ivermectin 6mg for sale mens ed pills order deltasone 5mg
buy levitra no prescription cost tizanidine 2mg hydroxychloroquine pills
ramipril over the counter purchase amaryl online cheap buy arcoxia paypal
order olmesartan 20mg without prescription divalproex 500mg drug order depakote 500mg generic