2010년 4월 17일 토요일

연결자료구조~

#include
#include


struct node {
int Data;
struct node *next;
};
struct node *head=NULL, *del_node;

//struct node *tmp=head, *del_node;

void main()
{
head = (struct node*)malloc(sizeof(struct node));
head ->Data = 5;
head ->next = (struct node*)malloc(sizeof(struct node));
head ->next->Data=3;
head ->next->next=(struct node*)malloc(sizeof(struct node));
head ->next->next->Data=45;
head ->next->next->next= (struct node*)malloc(sizeof(struct node));
head ->next->next->next->Data=21;
head ->next->next->next->next= (struct node*)malloc(sizeof(struct node));
head ->next->next->next->next->Data=9;
head ->next->next->next->next->next=NULL;


del_node = head;
head = head->next;
free(del_node);

while(head != NULL)
{
printf("%d \n", head->Data);
head = head ->next;
}

getchar();
}

댓글 없음:

댓글 쓰기