chiều cao của cay & so61 nút lá trong cây
Diễn đàn CK4 :: Góc học tập :: Năm I :: CTDL>
Page 1 of 1
chiều cao của cay & so61 nút lá trong cây
#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);
}
#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
- Tổng số bài gửi : 31
Join date : 2009-10-26
Age : 33
Đến từ : Bình Dương
Similar topics
» chiêu mộ nhân tài
» Tuyen bx trong Au nghen
» Chuyện lạ trên thế giới
» Trọng Thủy Mỵ Châu thời @ !!!
» Đề nghị anh em trong lớp tập trung đánh vài trận giao lưu đi
» Tuyen bx trong Au nghen
» Chuyện lạ trên thế giới
» Trọng Thủy Mỵ Châu thời @ !!!
» Đề nghị anh em trong lớp tập trung đánh vài trận giao lưu đi
Diễn đàn CK4 :: Góc học tập :: Năm I :: CTDL>
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|