#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAME 50
#define TRUE 1
typedef struct node *NodePointer;
typedef struct node {
int age;
char name[MAX_NAME];
NodePointer link;
} Node;
void Make_Node(NodePointer );
void Print_Node(NodePointer );
void Fine_Node(NodePointer );
void delete_Node(NodePointer);
int main( void )
{
int i,j;
int nember;
NodePointer head = NULL;
NodePointer temp = head;
while(TRUE)
{
printf("1) 입력 \n 2) 출력 \n3) 검색 \n 4) 삭제 \n 5) 종료\n");
scanf("%d",&nember);
switch(nember)
{
case 1:
Make_Node(&head);
break;
case 2:
Print_Node(head);
break;
case 3:
Fine_Node(head);
break;
case 4:
delete_Node(&head);
break;
case 5:
return 0;
break;
}
}
}
void Make_Node(NodePointer *temp)
{
int i;
NodePointer item;
NodePointer cur = *temp;
item = (NodePointer)malloc(sizeof(Node));
printf("이름 입력 : ");
scanf("%s", item->name);
printf("나이 입력 : ");
scanf("%d", &item->age);
item->link = NULL;
if(*temp == NULL)
{
*temp = item;
return ;
}
else
{
for( ; ; )
{
if((cur)->link == NULL)
{
(cur)->link = item;
break;
}
cur = cur->link;
}
}
}
void Print_Node(NodePointer temp)
{
for( ; temp != NULL ;temp = temp->link)
{
printf("이름 : %s ", temp->name);
printf("나이 : %d \n",temp->age);
}
}
void Fine_Node(NodePointer temp)
{
char findname[30];
printf("찾을 사람 이름 입력 :");
scanf("%s",findname);
for( ; temp != NULL ;temp = temp->link)
{
if(strcmp(temp->name,findname)== 0)
{
printf("이름 : %s ", temp->name);
printf("나이 : %d \n",temp->age);
break;
}
}
if(temp == NULL)
{
printf("찾는사람 없습니다.\n");
}
}
void delete_Node(NodePointer *node)
{
char findname[30];
NodePointer temp = *node;
NodePointer item;
printf("지울 사람 이름 입력 :");
scanf("%s",findname);
for( ; temp != NULL ;temp = temp->link)
{
if(strcmp(temp->name,findname)== 0)
{
printf("이름 : %s ", temp->name);
printf("나이 : %d \n",temp->age);
item->link = temp->link;
free(temp);
break ;
}
item = temp;
}
if(temp == NULL)
{
printf("찾는사람 없습니다.\n");
}
}
'Programming > C&C++&C#' 카테고리의 다른 글
[C++] C++ 다이아몬드 만들기 (0) | 2013.12.27 |
---|---|
[C언어] 문자, 문자열 입력 (0) | 2013.10.04 |
[C언어] 주소록 linked list + file I/O (0) | 2013.07.31 |
[C++] 참조자 (0) | 2013.06.21 |
[C언어] C 언어 포멧 문자, 특수 문자, 입출력 스트림 (0) | 2013.06.15 |