프로그래밍 수행평가

#include<stdio.h>
#include<alloc.h>
struct list_node{
int data;
struct list_node *link;
};
struct list_node *create();
void list_print(struct list_node *);
void delete_node(struct list_node *);
void create_node(struct list_node *);
void main(){
struct list_node *head;
int select;
head = create();
do{
printf("메뉴 : 1.삭제&출력 2.삽입&출력 0.종료 ");
scanf("%d",&select);
if(select==1){
 delete_node(head);
 list_print(head);
}
else if(select==2){
 create_node(head);
 list_print(head);
}
}while(select != 0);
 printf("프로그램이 종료 되었습니다.");
 free(head);
}
struct list_node *create(){
 struct list_node *first , *second;
 first = (struct list_node *)malloc(sizeof(struct list_node));
 second = (struct list_node *)malloc(sizeof(struct list_node));
 second->link = NULL;
 second->data = 20;
 first->data = 10;
 first->link = second;
 return first;
}
void create_node(struct list_node *ptr){
 for(;ptr->link;ptr = ptr->link){}
 struct list_node *other;
 other = (struct list_node *)malloc(sizeof(struct list_node));
 scanf("%d", &other->data);
 other->link = NULL;
 ptr->link = other;
}
void delete_node(struct list_node *ptr){
 for(;ptr;ptr = ptr->link)
  if(ptr->link->link == NULL) break;
 ptr->link = NULL;
}
void list_print(struct list_node *ptr){
 for(;ptr;ptr = ptr->link)
  printf("%d ",ptr->data);
}


후럴 -_-

by JAAE | 2005/12/06 21:36 | 트랙백 | 덧글(0)

트랙백 주소 : http://JAAE.egloos.com/tb/1999897
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]

:         :

:

비공개 덧글

◀ 이전 페이지          다음 페이지 ▶