소개글
거의 완벽하다고 생각됩니다.컴파일 실행환경
C++로 짠 트리구조입니다.본문내용
/*============================================Tree & Simple Linked List (Anniversary)
============================================*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
struct BTREE{
char group[10]; // 그룹명(사용자명)
struct LINKLIST *anni; // Anniversary(LinkList)의 head주소
struct BTREE *left_child; // Child
struct BTREE *right_sibling; // Sibling
};
struct LINKLIST{
int month, date; // 기념일 날짜(월, 일)
char memo[100]; // 기념일 내용
struct LINKLIST *link; // 다음 노드의 주소
};
struct BTREE *root; // Root 노드 생성
struct BTREE *current_tree; // 현재 트리 노드의 주소
/*---------------------------------
add_tree()
Tree노드를 추가한다.
input : 추가할 그룹명(사용자명)
---------------------------------*/
void add_tree(char group[10]){
// 트리의 새로운 노드 , 마지막 Sibling노드
struct BTREE *new_tree, *last, *last_sibling(), *sch_tree, *search_tree();
//void search_tree();
new_tree = (struct BTREE*)malloc(sizeof(struct BTREE));
// Root노드 생성
if(root == NULL){
root = current_tree = new_tree;
strcpy(new_tree->group, group);
new_tree->anni = NULL;
new_tree->left_child = NULL;
new_tree->right_sibling = NULL;
printf("\nRoot 노드입니다.\n\n");
printf("그룹(사용자)이 성공적으로 추가되었습니다.\n");
getch();
return;
}
sch_tree = search_tree(current_tree->left_child, group);
if(sch_tree){
printf("같은 이름의 하위 그룹이 이미 존재합니다.\n");
getch();
return;
}
// 현재 노드에서 Child 추가
if((current_tree->left_child) == NULL){
current_tree->left_child = new_tree;
strcpy(new_tree->group, group);
new_tree->anni = NULL;
new_tree->left_child = NULL;
new_tree->right_sibling = NULL;
printf("그룹(사용자)이 성공적으로 추가되었습니다.\n");
getch();
return;
}
// 하위 노드의 Sibling 추가
if(current_tree->left_child){
last = last_sibling();
last->right_sibling = new_tree;
strcpy(new_tree->group, group);
new_tree->anni = NULL;
new_tree->left_child = NULL;
new_tree->right_sibling = NULL;
printf("그룹(사용자)이 성공적으로 추가되었습니다.\n");
getch();
return;
}
}
압축파일 내 파일목록
Tree.plg
Tree.c
Tree.ncb
Tree.opt
Debug/Tree.exe
Debug/Tree.ilk
Debug/Tree.obj
Debug/Tree.pch
Debug/Tree.pdb
Debug/vc60.idb
Debug/vc60.pdb
Tree.dsp
Tree.dsw
Tree.c
Tree.ncb
Tree.opt
Debug/Tree.exe
Debug/Tree.ilk
Debug/Tree.obj
Debug/Tree.pch
Debug/Tree.pdb
Debug/vc60.idb
Debug/vc60.pdb
Tree.dsp
Tree.dsw
참고 자료
없음프로그램소스 연관자료
이 자료와 함께 구매한 자료
- [자료구조][C++] Tree (자료구조) 0페이지
- [자료구조]이진트리(삽입,삭제,탐색) 6페이지
- 이진탐색트리의 생성 및 탐색 및 출력 7페이지
- 이진트리 삽입,삭제 0페이지
- txt파일 입출력을 통한 성적관리프로그램 0페이지