Diễn đàn CK4
Would you like to react to this message? Create an account in a few clicks or log in to continue.

chiều cao của cay & so61 nút lá trong cây

Go down

chiều cao của cay & so61 nút lá trong cây Empty chiều cao của cay & so61 nút lá trong cây

Post by nhoc1rang 2010-05-30, 7:11 pm

#include <stdio.h>
#include <conio.h>
struct node
{
int key;
struct node *pLeft;
struct node *pRight;
};
typedef struct node NODE;
typedef NODE *TREE;

int BSTDelete(NODE *&pCurr, int Key)
{
if (pCurr==NULL)
return 0;
if (pCurr->key > Key)
return BSTDelete(pCurr->pLeft, Key);
else if (pCurr->key < Key)
return BSTDelete(pCurr->pRight, Key);
_Delete(pCurr);
return 1;
}

void _Delete(NODE *&pCurr)
{
NODE *pTemp = pCurr;
if (pCurr->pRight==NULL)
pCurr = pCurr->pLeft;
else if (pCurr->pLeft==NULL)
pCurr = pCurr->pRight;
else
pTemp = _SearchStandFor(pCurr->pLeft, pCurr);
delete pTemp;
}
NODE * _SearchStandFor(NODE *&p, NODE *pCurr) //Tim doi tuong de xoa0
{
if (p->pRight != NULL)
return _SearchStandFor(p->pRight, pCurr);
pCurr->key = p->key;
NODE *pTemp = p;
p = p->pLeft;
return pTemp;
}
int DemSoNutLa(NODE *p)
{
if(p==NULL)
return 0;
if(p->pLeft == NULL && p->pRight != NULL)
return DemSoNutLa(p->pRight);
if(p->pLeft != NULL && p->pRight ==NULL)
return DemSoNutLa(p->pLeft);
if(p->pRight != NULL && p->pLeft != NULL)
return DemSoNutLa(p->pLeft) + DemSoNutLa(p->pRight);
if(p->pLeft ==NULL && p->pRight == NULL)
return 1;
return DemSoNutLa(p);
}
void XoaSoAm(NODE *&p)
{
if(p==NULL)
return;
if(p->key <0)
_Delete(p);

XoaSoAm(p->pLeft);
XoaSoAm(p->pRight);
}

nhoc1rang
Mới vào mầm non
Mới vào mầm non

Tổng số bài gửi : 31
Join date : 2009-10-26
Age : 33
Đến từ : Bình Dương

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum