링크드리스트 트리 전화번호부 관리
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);
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2694854 | 절대값을 구할때 (2) | 그녀는귀여웠다 | 2025-05-15 |
2694827 | 이제 어떻게 공부해야할지 모르겠네요 | 새얀 | 2025-05-14 |
2694778 | 순열 계산요. | 맛조이 | 2025-05-14 |
2694754 | ShowWindow 함수를 이용하려 하는데 질문있습니다. (2) | 파도 | 2025-05-14 |
2694731 | 리눅스 커널의 시작점 질문 | 미르 | 2025-05-13 |
2694702 | 이거 뭐가문제인가요 코드수정좀 (3) | 맑은 | 2025-05-13 |
2694675 | C언어 후위표기를 중위표기로 | 앨런 | 2025-05-13 |
2694646 | 안녕하세요 파일 합치기 함수! (1) | 연블루 | 2025-05-13 |
2694618 | 잘몰라서 설명부탁드립니다. scanf 관련 (3) | 파라 | 2025-05-12 |
2694590 | 이 코드가 뭐하는 코드일까요? #2 | 빵순 | 2025-05-12 |
2694559 | 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) | 늘솔길 | 2025-05-12 |
2694532 | 네트워크에 관하여... (4) | 황소자리 | 2025-05-12 |
2694503 | 프로그램 연산 후 바로 종료되는 현상 (6) | Judicious | 2025-05-11 |
2694450 | while문질문입니다. (1) | 허리품 | 2025-05-11 |
2694420 | C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) | 은새 | 2025-05-11 |
2694370 | 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 | 들찬 | 2025-05-10 |
2694339 | putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) | 미르 | 2025-05-10 |
2694316 | 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) | 나빛 | 2025-05-10 |
2694285 | 언어 공부하는 과정 좀 추천해주세요! (1) | 아빠몬 | 2025-05-09 |
2694258 | 카운터.. 질문입니다. (4) | 하늘빛눈망울 | 2025-05-09 |