b트리를 설계하라
본 자료는 3페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
해당 자료는 3페이지 까지만 미리보기를 제공합니다.
3페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

b트리를 설계하라에 대한 보고서 자료입니다.

목차

없음

본문내용

ent->count;i++)
printf(\" %c \",current->key[i]);
cout< for(i=0;i<=current->count;i++) {
dispTree(current->ptr[i]);
}
cout< }
}
// 트리의 출력 public
void BTree::disp()
{
cout<< \"-----------------------------------------\\n\"
<< \" B-Tree Status \\n\"
<< \"-----------------------------------------\\n\"
<< \" 트리의 최대키 : \" << MAX << endl
<< \" 트리의 최소키 : \" << MIN << endl
<< \" \'-\' 는 비어있는 자식노드\\n\"
<< \"-----------------------------------------\\n\";
dispTree(root);
cout< }
b-tree1.cpp
#include \"BTree.h\"
#include
#include
using namespace std;
int mainmenu()
{
cout << \" B트리 선택메뉴.\\n\"
<< \"-----------------------------------------\\n\"
<< \" 1. 삽입\\n\"
<< \" 2. 삭제\\n\"
<< \" 3. 검색\\n\"
<< \" 4. 현재 B-Tree 상태 보기\\n\"
<< \" 0. 종료\\n\"
<< \"-----------------------------------------\\n\"
<< \" -> \";
return 1;
}
int PressKey()
{
char x;
cout << \"Press ENTER\";
fflush(stdin);
cin.get(x);
fflush(stdin);
return 1;
}
void main()
{
BTree btree;
element loc;
char op=\'1\';
char x;
while(op!=\'0\') {
fflush(stdin);
system(\"cls\");
mainmenu();
cin.get(op);
fflush(stdin);
switch(op) {
case \'1\':
cout << \"삽입 할 인덱스(character) : \";
fflush(stdin);
cin.get(x);
fflush(stdin);
btree.Insert(x);
PressKey();
break;
case \'2\':
cout << \"삭제 할 인덱스(character) : \";
fflush(stdin);
cin.get(x);
fflush(stdin);
btree.Delete(x);
PressKey();
break;
case \'3\':
cout << \"찾을 인덱스(character) : \";
fflush(stdin);
cin.get(x);
fflush(stdin);
loc=btree.SearchTree(x);
if(!loc.tag) cout << \"트리 내에서 해당 인덱스를 발견하였습니다.\"< else cout << \"트리 내에서 해당 인덱스는 존재하지 않습니다.\"< PressKey();
break;
case \'4\':
btree.disp();
PressKey();
break;
case \'0\':
cout << \"요청에 의해 프로그램을 종료합니다.\" << endl;
return;
break;
default:
cout << \"없는 명령입니다. 메뉴번호를 확인하세요.\" << endl;
PressKey();
break;
}
}
}
BTree.h
#ifndef BTREE_H
#define BTREE_H
#define MAX 4
#define MIN 2
#define TRUE 1
#define FALSE 0
typedef int BOOL;
struct TreeNode
{
int count;
TreeNode *parent;
int key[MAX+1];
TreeNode *ptr[MAX+1];
};
struct element
{
TreeNode *r;
int i;
int tag;
};
class BTree
{
public:
BTree();
~BTree();
void disp();
element SearchTree(const int x);
TreeNode *Insert(const int x);
BOOL Delete(const int &x);
private:
TreeNode *root;
BOOL SearchNode(const int x, TreeNode *current, int *pos);
BOOL PushDown(int newentry, TreeNode *current, int *midNode, TreeNode **midright);
void PushIn(int midNode, TreeNode *midright, TreeNode *current, int pos);
void Split(int midNode, TreeNode *midright, TreeNode *current,int pos, int *newmedian, TreeNode **newright);
void LeftAdjust(TreeNode *p, TreeNode *q, int d, int j);
void RightAdjust(TreeNode *p, TreeNode *q, int d, int j);
void compress(TreeNode *p, int j);
void merge(TreeNode *p, TreeNode *q, TreeNode *p1, int j);
TreeNode *Search(const int x, TreeNode *current, int &pos);
void dispTree(TreeNode *current);
int m;
};
#endif
코드완성 후 컴파일해서 실행시키면 첫화면 메뉴 선택화면
1.삽입 : 삽입이 되었을때와 이미 적용된 수과 또 적용 되면 오류발생 화면
2.삭제
3.검색:검색 성공시와 트리내 없을 때
상태표현(삽입시 줄이 다차면 자식노드로 내려가는 것 표현 )
3차 b트리가 완성된다
  • 가격13,860
  • 페이지수11페이지
  • 등록일2014.04.01
  • 저작시기2014.1
  • 파일형식한글(hwp)
  • 자료번호#910943
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니