b트리 구현인데요 레벨오더루 출력하는 방법좀
글쓴이: blueadol / 작성시간: 화, 2004/12/21 - 4:18오후
b-tree에서
삽입된 데이터를 출력하려고 합니다..
만약트리가
[10]
[5] [15]
[1,3] [7] [11] [17,18]
이렇게 있으면 지금은
10
5
15
1 3
7
11
17 18
일케 출력이 됩니다.
이걸
[10]
[5][15]
[1,3][7][11][17,18]
이렇게 출력 하려고 하면 어케 해야 할까요??
고수님들의 답변바랍니다
도와주세유 ㅠ_ㅠ 시간이 엄써서여...
출력함수부분이랑 큐함수 부분에 손을 봐야 할꺼 같은데
어케 해야하는지 자세히좀 ㅡ.ㅡ 가르쳐주세용...
/*>>> FUNCTION >>> B Tree의 현재 내용을 출력하는 함수(LEVEL ORDER TRAVERSAL) */ /*>>> CALL FUNCTION >>> NONE */ void data_view(){ /* local variable declaration */ que_ptr front=NULL, rear=NULL; // index variable declaration of queue & initial tree_ptr temp = root; // address assignment if(!temp){ // case : empty tree (error message print & return) printf("\n<WARNNING> NONE DATA IN TREE\n\a"); return; } queue_insert(&front, &rear, temp); // queue insertion while(1){ temp = queue_delete(&front); // queue deletion printf("\n"); if(temp){ // case : temp != NULL if(temp->key1!=INT_MAX) printf("%d ", temp->key1); if(temp->key2!=INT_MAX) printf("%d ", temp->key2); if(temp->left) queue_insert(&front, &rear, temp->left); if(temp->middle) queue_insert(&front, &rear, temp->middle); if(temp->right) queue_insert(&front, &rear, temp->right); } else break; // case : temp == NULL } printf("\n"); } /*>>> FUNCTION >>> QUEUE의 INSERTION 연산을 수행하는 함수(노드의 주소 저장) */ /*>>> CALL FUNCTION >>> NONE */ void queue_insert(que_ptr *front, que_ptr *rear, tree_ptr ads){ /* local variable declaration */ que_ptr temp = (que_ptr)malloc(sizeof(queue)); // dynamic allocation if(!temp){ // case : failed allocation (error message print & exit) printf("\n<WARNNING> MEMORY IS FULL!!!\n"); exit(1); } temp->ads = ads; // address : save temp->link = NULL; // link : save if(*front) (*rear)->link = temp; else (*front) = temp; (*rear) = temp; } /*=====================================================================================*/ /******************************** queue_delete() FUNCTION ******************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> QUEUE의 DELETION 연산을 수행하는 함수(노드의 주소 리턴) */ /*>>> CALL FUNCTION >>> NONE */ tree_ptr queue_delete(que_ptr *front){ /* local variable declaration */ que_ptr temp = (*front); // address assignment tree_ptr item; if(!temp) return 0; item = temp->ads; // address : save (*front) = temp->link; // link : save free(temp); return item; }[/code]
File attachments:
첨부 | 파일 크기 |
---|---|
![]() | 22.22 KB |
Forums:
고수님들의 많은참여 부탁드립니다.
고맙습니다.
댓글 달기