/*------------------------------------------------------------------------------------------
다음은 double linked-list를 구현한 프로그램의 일부분이다.
함수의 본체를 구현 하시오.
-------------------------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
/* 노드 자료 구조 정의 */
struct node {
int item; /* 값 */
struct node* prev; /* 이전 노드에 대한 포인터 */
struct node* next; /* 다음 노드에 대한 포인터 */
};
/* 함수 prototype 선언 */
struct node* insert(struct node** head, int v);
void delete(struct node** head, int v);
void print_list(struct node* head);
void clear_list(struct node* head);
int main()
{
int data[5] = {4, 2, 5, 7, 10 };
struct node* head = NULL;
insert(&head, data[0]);
printf("insert %d\n", data[0]);
print_list(head);
printf("------------------------\n");
insert(&head, data[1]);
printf("insert %d\n", data[1]);
print_list(head);
printf("------------------------\n");
insert(&head, data[2]);
printf("insert %d\n", data[2]);
print_list(head);
printf("------------------------\n");
delete(&head, data[0]);
printf("delete %d\n", data[0]);
print_list(head);
printf("------------------------\n");
delete(&head, data[1]);
printf("delete %d\n", data[1]);
print_list(head);
printf("------------------------\n");
delete(&head, data[2]);
printf("delete %d\n", data[2]);
print_list(head);
printf("------------------------\n");
clear_list(head);
return 0;
}
/*-----------------------------------------------------------------------------------------------
insert(head, v) : heard가 가리키는 리스트에 v를 오름차순으로 정렬하여 삽입한다.
head : 더블 링크르 리스트의 header 포인터
v : 삽입할 값
return value : 새로 생성된 노드에 대한 포인터
------------------------------------------------------------------------------------------------*/
struct node* insert(struct node** head, int v)
{
}
/*-----------------------------------------------------------------------------------------------
delete(head, v) : head가 가리키는 리스트에서 v를 삭제한다.(v는 반드시 존재한다고 가정한다.)
head : 더블 링크르 리스트의 header 포인터
v : 리스트에서 삭제할 값
------------------------------------------------------------------------------------------------*/
void delete(struct node** head, int v)
{
}
/*-----------------------------------------------------------------------------------------------
print_list(head) : 헤드가 가리키는 리스트의 내용을 출력한다.
head : 더블 링크르 리스트의 header 포인터
------------------------------------------------------------------------------------------------*/
void print_list(struct node* head)
{
}
/*-----------------------------------------------------------------------------------------------
clear_list(head) : 헤드가 가리키는 리스트의 모든 노드를 삭제한다.
head : 더블 링크르 리스트의 header 포인터
------------------------------------------------------------------------------------------------*/
void clear_list(struct node* head)
{
}
|