링크드리스트 트리 전화번호부 관리
Together
링크드 리스트+ 이진트리 구현하는 프로그램인데요
다 링크드 리스트로 구현하고
key를 이름으로 하여 전위,중위,후위 검색 프로그램을 만드는 것인데,
다른것은 다했는데, 전위,중위,후위검색을 어떻게 구현해야할지 모르겟네요.
고수님들 도와주세요 ㅠ.ㅠ...
더이상 어떻게 해야할지 모르겟네요 ㅠ.ㅠ...
조금 급해서리 잘부탁드려요 ㅠ.ㅠ..
#include stdio.h
#include string.h
#include stdlib.h
#include conio.h
#include memory.h
typedef struct
{
char name[20];
char phone[40];
char address[50];
}telnode;
struct link_node
{
telnode item;
struct link_node *next;
};
typedef struct link_node Pbook;
typedef struct link_node *Plink;
typedef struct TreeNode {
char name;
struct TreeNode *left, *right;
} TreeNode;
void insert(telnode temp, Plink *head_node)
{
Plink temp_node=*head_node;
Plink New_node;
New_node = (Plink) malloc(sizeof(Pbook));
New_node-item=temp;
New_node-next=NULL;
if(*head_node)
{
while(temp_node-next)
temp_node=temp_node-next;
temp_node-next=New_node;
}
else
*head_node=New_node;
}
telnode del_list(char name[], Plink *head_node)
{
Plink temp=*head_node;
Plink deltemp=temp-next;
telnode temp_node;
if(!head_node)
{
printf(입력된 자료가 없습니다.\n);
exit(1);
}
else
{
if(strcmp(temp-item.name, name)==0)
{
temp_node=temp-item;
*head_node=deltemp;
free(temp);
return temp_node;
}
else
{
while(deltemp)
{
if(strcmp(deltemp-item.name, name)==0)
{
temp_node = deltemp-item;
temp-next=deltemp-next;
free(deltemp);
return temp_node;
}
else
{
temp=deltemp;
deltemp=deltemp-next;
}
}
}
}
printf(%s 를 찾을 수가 없습니다.\n);
strcpy(temp_node.name,error);
return temp_node;
}
void search_data(char sdata[], Plink *head_node)
{
Plink temp=*head_node;
if(!head_node)
{
printf(입력된 데이터가 없습니다.\n);
exit(1);
}
else
{
while(temp)
{
if(strcmp(temp-item.name, sdata)==0)
{
printf(\n **검색 결과**\n 이름 : %s, 전화번호 : %s, 주소 : %s\n, temp-item.name, temp-item.phone, temp-item.address);
return;
}
temp=temp-next;
}
printf(데이타를 찾을 수 없습니다.\n);
}
}
void print_list(Plink *head_node)
{
Plink temp=*head_node;
if(!temp)
printf(\n 현재 입력된 내용이 없습니다.\n);
while(temp)
{
printf(이름 : %s\n, temp-item.name);
printf(전화번호 : %s\n, temp-item.phone);
printf(주소 : %s\n, temp-item.address);
temp=temp-next;
}
}
void inorder (TreeNode *root)
{
if (root) {
inorder(root-left);
printf(%c, root-name);
inorder(root-right);
}
}
void preorder(TreeNode* root)
{
if(root) {
printf(%c, root-data);
preorder(root-left);
preorder(root-right);
}
}
void postorder(TreeNode* root)
{
if(root) {
postorder(root-left);
postorder(root-right);
printf(%c, root-data);
}
}
void menu(int select, Plink *A)
{
telnode temp;
char sdata[15];
char c;
switch(select)
{
case 1:
printf(이름 : );
scanf(%s, &temp.name);
printf(전화번호 : );
scanf(%s, &temp.phone);
printf(주소 : );
scanf(%s, &temp.address);
insert(temp, A);
printf(입력이 완료되었습니다.);
c = getch();
break;
case 2:
printf(검색할 이름을 입력하세요 : );
scanf(%s, &sdata);
search_data(sdata, A);
c = getch();
break;
case 3:
printf(삭제할 이름을 입력하시오 :);
scanf(%s, &sdata);
temp=del_list(sdata, A);
printf(삭제가 완료 되었습니다.);
c = getch();
break;
case 4:
printf(현재 입력된 결과를 출력합니다.\n);
print_list(A);
c = getch();
break;case 8:
printf(모든 작업을 종료합니다.\n);
exit(0);
break;
default :;
}
}int main()
{
Plink A=NULL;
int select;
while(select !=8)
{
system(cls);
printf(******************* TelePhone ******************************************************\n);
printf(1. 입력 2. 검색 3. 삭제 4. 모두검색 5. 전위검색 6. 중위검색 7. 후위검색8. 종료\n);
printf(*************************************************************************************\n);
printf(메뉴 선택:);
scanf(%d, &select);
menu(select, &A);
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2697737 | 정올 문제좀 풀어보신분~ | 레오 | 2025-06-10 |
2697709 | rand함수 질문좀요! (6) | 가막새 | 2025-06-10 |
2697683 | C언어 변수뒤 표시가 이해안되는게 있습니다. | 소미 | 2025-06-10 |
2697660 | 껍데기딜 만들고 난후 어느핫키 누르면 코드검색이라도 뜨고 그다음 무반응 해결좀 (2) | 움찬 | 2025-06-09 |
2697634 | c언어로 감성사전 만들기! (1) | 도란도란 | 2025-06-09 |
2697605 | 이 함수좀... | agine | 2025-06-09 |
2697574 | 배열 기본적인질문 (3) | 민트향 | 2025-06-09 |
2697549 | 배열 초기화 (4) | 나리 | 2025-06-08 |
2697465 | 수다님...^^ (2) | 가론 | 2025-06-08 |
2697432 | 서버 만드는 함수에서 궁금한게있어요~ | 파랑 | 2025-06-07 |
2697401 | 열혈강의 문제오류 (1) | 꿈 | 2025-06-07 |
2697374 | 기초적인 C언어 프로그래밍 입니다. | 얼 | 2025-06-07 |
2697341 | 좌우대칭 문제인데 Q가 입력되면 종료가 되야하는데 되지않습니다 | 무지개 | 2025-06-07 |
2697314 | fprintf와 fscanf 로 파일 입출력 할떄 | 밝음이 | 2025-06-06 |
2697293 | 툴 소스 뽑아내는법 | 도움 | 2025-06-06 |
2697264 | 소소한거 두어가지 질문할께요~ (8) | 별솔 | 2025-06-06 |
2697235 | scanf로 인풋 받을 때?! | 보담 | 2025-06-06 |
2697207 | 열혈강의 연습문제 질문이요~ (2) | 맥적다 | 2025-06-05 |
2697182 | strcmp, strtok - 어떤 기능을 하는지... | 루다 | 2025-06-05 |
2697129 | [질문] 아래 저축액을 계산하는 프로그램 ㅠ 추가 질문 (7) | 찬늘 | 2025-06-05 |