#include <Turboc.h>
// 노드 구조체
struct Node
{
int value;
Node *next;
};
Node *head;
// 연결 리스트 초기화 - 머리를 할당한다.
void InitList()
{
head=(Node *)malloc(sizeof(Node));
head->next=NULL;
}
// Target 다음에 노드를 삽입한다.
Node *InsertNode(Node *Target,Node *aNode)
{
Node *New;
New=(Node *)malloc(sizeof(Node));
*New=*aNode;
New->next=Target->next;
Target->next=New;
return New;
}
// Target 다음 노드를 삭제한다.
BOOL DeleteNode(Node *Target)
{
Node *Del;
Del=Target->next;
if (Del==NULL) {
return FALSE;
}
Target->next=Del->next;
free(Del);
return TRUE;
}
// 연결 리스트의 모든 노드와 머리를 해제한다.
void UnInitList()
{
while (DeleteNode(head)) {;}
free(head);
head=NULL;
}
void main()
{
int i;
Node *Now,Temp;
InitList();
// 다섯 개의 노드 삽입
Now=head;
for (i=1;i<=5;i++) {
Temp.value=i;
Now=InsertNode(Now,&Temp);
}
// 두 번째 노드 삭제
DeleteNode(head->next);
// 순회하면서 출력
for (Now=head->next;Now;Now=Now->next) {
printf("%d\t",Now->value);
}
printf("\n");
UnInitList();
}
----------------------------------------------------------
이건데
Node *InsertNode(Node *Target,Node *aNode)
{
Node *New;
New=(Node *)malloc(sizeof(Node));
*New=*aNode;
New->next=Target->next;
Target->next=New;
return New;
}
New->next=Target->next; 이게 의미 하는게 머죠? 해석을 어떻게 해야될지모르겟음. 자세하게 알려주실분.
싱글 링크드 리스트니까 타겟과 타겟의 넥스트 사이에 뉴를 넣어야하저?
그래서 뉴의 넥스트를 타겟의 넥스트라고 하게 한 뒤 타겟의 넥스트를 뉴로 넣으면 뉴가 그 사이에 가는 그림이 그려지져?
그거에여
그림 그려 그림 그림이 짱이야
언제적 터보씨냐....