[알고리즘] 이진검색트리(Binary Search Tree) 삽입, 검색, 삭제
- 최초 등록일
- 2011.06.23
- 최종 저작일
- 2009.11
- 압축파일
- 가격 2,000원
소개글
이진검색트리를 구현하여 데이터를 삽입, 검색, 삭제하는 프로그램입니다.
명령인수로 텍스트파일이름을 받아서 텍스트파일에 있는 명령(삽입, 검색, 삭제)을 파싱해 실행합니다.
한국산업기술대학교 게임공학과 오황석 교수님 알고리즘 과제입니다.
< example >
Search(15)
Insert(15, "1515")
Delete(15)
컴파일 실행환경
Microsoft Visual C++ 6
본문내용
int Delete(int key, NODE* base)
{
NODE *parent, *son, *del, *nexth;
int depth = 0;
parent = base;
del = base->left;
while(del != NULL && key != del->key)
{
parent = del;
if (key < del->key)
{
del = del->left;
depth++;
}
else
{
del = del->right;
depth++;
}
}
if (del == NULL)
{
return -1;
}
if (del->right == NULL) //유형1. 삭제할 노드의 오른쪽 자식이 없는 경우
{
son = del->left;
}
else if(del->right->left == NULL) //유형2. 삭제할 노드의 오른쪽 자식의 왼쪽 자식이 없는 경우
{
son = del->right;
son->left = del->left;
}
else
{
nexth = del->right;
while (nexth->left->left != NULL)
{
nexth = nexth->left;
} //오른쪽 자식의 최소 노드
son = nexth->left;
압축파일 내 파일목록
BinaryTree.cpp
BinaryTree.exe
testData_6_1_1.txt
testData_6_1_2.txt
testData_6_1_3.txt
참고 자료
없음