트리(tree)관련 프로그래밍 소스 모음 (C언어)
본 자료는 5페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
해당 자료는 5페이지 까지만 미리보기를 제공합니다.
5페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

트리(tree)관련 프로그래밍 소스 모음 (C언어)에 대한 보고서 자료입니다.

본문내용

, *n5, *n6;
n1 = (tnode_str*)malloc(sizeof(tnode_str));
n2 = (tnode_str*)malloc(sizeof(tnode_str));
n3 = (tnode_str*)malloc(sizeof(tnode_str));
n4 = (tnode_str*)malloc(sizeof(tnode_str));
n5 = (tnode_str*)malloc(sizeof(tnode_str));
n6 = (tnode_str*)malloc(sizeof(tnode_str));
n1->data = 10;
n1->left_child = n2;
n1->right_child = n3;
n2->data = 20;
n2->left_child = n4;
n2->right_child = n5;
n3->data = 30;
n3->left_child = n6;
n3->right_child = NULL;
n4->data = 40;
n4->left_child = NULL;
n4->right_child = NULL;
n5->data = 50;
n5->left_child = NULL;
n5->right_child = NULL;
n6->data = 60;
n6->left_child = NULL;
n6->right_child = NULL;
root = n1;
inorder (root);
printf("\n");
free (n1);
free (n2);
free (n3);
free (n4);
free (n5);
free (n6);
}
8.다음의 후위와 전위 순회하는 함수를 5번 코드에 추가하여 트리에 존재하는 노드의 내용을 출력하라.
(1) 전위순회
#include
#include
#include
typedef struct tree_node
{
int data;
struct tree_node *left_child, *right_child;
} tnode_str;
tnode_str *root;
void inorder (tnode_str *ptr)
{
if (ptr)
{
printf("<%d>", ptr->data);
inorder (ptr->left_child);
inorder (ptr->right_child);
}
}
void main()
{
tnode_str *n1, *n2, *n3, *n4, *n5, *n6;
n1 = (tnode_str*)malloc(sizeof(tnode_str));
n2 = (tnode_str*)malloc(sizeof(tnode_str));
n3 = (tnode_str*)malloc(sizeof(tnode_str));
n4 = (tnode_str*)malloc(sizeof(tnode_str));
n5 = (tnode_str*)malloc(sizeof(tnode_str));
n6 = (tnode_str*)malloc(sizeof(tnode_str));
n1->data = 10;
n1->left_child = n2;
n1->right_child = n3;
n2->data = 20;
n2->left_child = n4;
n2->right_child = n5;
n3->data = 30;
n3->left_child = n6;
n3->right_child = NULL;
n4->data = 40;
n4->left_child = NULL;
n4->right_child = NULL;
n5->data = 50;
n5->left_child = NULL;
n5->right_child = NULL;
n6->data = 60;
n6->left_child = NULL;
n6->right_child = NULL;
root = n1;
inorder (root);
printf("\n");
free (n1);
free (n2);
free (n3);
free (n4);
free (n5);
free (n6);
}
(2) 후위순회
#include
#include
#include
typedef struct tree_node
{
int data;
struct tree_node *left_child, *right_child;
} tnode_str;
tnode_str *root;
void inorder (tnode_str *ptr)
{
if (ptr)
{
inorder (ptr->left_child);
inorder (ptr->right_child);
printf("<%d>", ptr->data);
}
}
void main()
{
tnode_str *n1, *n2, *n3, *n4, *n5, *n6;
n1 = (tnode_str*)malloc(sizeof(tnode_str));
n2 = (tnode_str*)malloc(sizeof(tnode_str));
n3 = (tnode_str*)malloc(sizeof(tnode_str));
n4 = (tnode_str*)malloc(sizeof(tnode_str));
n5 = (tnode_str*)malloc(sizeof(tnode_str));
n6 = (tnode_str*)malloc(sizeof(tnode_str));
n1->data = 10;
n1->left_child = n2;
n1->right_child = n3;
n2->data = 20;
n2->left_child = n4;
n2->right_child = n5;
n3->data = 30;
n3->left_child = n6;
n3->right_child = NULL;
n4->data = 40;
n4->left_child = NULL;
n4->right_child = NULL;
n5->data = 50;
n5->left_child = NULL;
n5->right_child = NULL;
n6->data = 60;
n6->left_child = NULL;
n6->right_child = NULL;
root = n1;
inorder (root);
printf("\n");
free (n1);
free (n2);
free (n3);
free (n4);
free (n5);
free (n6);
}

키워드

C,   C언어,   트리,   tree,   소스,   source
  • 가격2,000
  • 페이지수16페이지
  • 등록일2004.11.28
  • 저작시기2004.11
  • 파일형식한글(hwp)
  • 자료번호#275854
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니