Giáo trình Cấu trúc dữ liệu và giải thuật[bookbooming.com]

Page 222

Giaùo trình: Caáu Truùc Döõ Lieäu vaø Giaûi Thuaät { BALTree = BALTree->BAL_Left; BALTree->BAL_Left = NULL; } } else // nuùt caàn huûy laø nuùt trung gian { if (BALTree->BAL_Left == NULL && BALTree->BAL_Right == NULL) if (OnTheLeft == 1) PrDNode->BAL_Left = NULL; else PrDNode->BAL_Right = NULL; else if (BALTree->BAL_Left == NULL) { if (OnTheLeft == 1) PrDNode->BAL_Left = BALTree->BAL_Right; else PrDNode->BAL_Right = BALTree->BAL_Right; BALTree->BAL_Right = NULL; } else if (BALTree->BAL_Right == NULL) { if (OnTheLeft == 1) PrDNode->BAL_Left = BALTree->BAL_Left; else PrDNode->BAL_Right = BALTree->BAL_Left; BALTree->BAL_Left = NULL; } } if (BALTree->BAL_Left != NULL && BALTree->BAL_Right != NULL) { BAL_Type MLNode = BALTree->BAL_Right; BAL_Type PrMLNode = BALTree; while (MLNode->BAL_Left != NULL) { PrMLNode = MLNode; MLNode = MLNode->BAL_Left; } BALTree->Key = MLNode->Key; if (PrMLNode == BALTree) PrMLNode->BAL_Right = MLNode->BAL_Right; else PrMLNode->BAL_Left = MLNode->BAL_Right; MLNode->BAL_Right = NULL; BALTree = MLNode; } delete BALTree; return (1); }

Trang: 222


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.