~cpp
// 호 ㅋㅋㅋㅋㅋㅋㅋㅋ
/*
int a; //
a = 10; //
int b = 10; // &
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _slist List;
typedef struct _slist{ //
int num;
List *next;
List *prev;
}List;
/*
struct _slist{
int num;
List *next;
List *prev;
};
typedef 'strucrt _slist' List 한.
, "List *aaa" == "struct _slist *aaa"
*/
#include "ExList.h"
void ShowList(List *plist)
{
List *p; // .
p=plist;
while(p)
{
printf("%d\n",p->num);
p=p->next;
}
}
void main()
{
List *pList,*pNew,*pIns; // struct _slist *pList, *pNew, *pIns; 3
pList=(List *)malloc(sizeof(List)); // malloc (List *) 크 List 하 환한. pList ().
pList->next=0; // 표한. 0.
pList->prev=0; // 표한.
pList->num=1; // 호 1 표한.
printf("root\n"); // *pList root 한.
ShowList(pList);
pNew=(List *)malloc(sizeof(List));
pList->next=pNew; // pList struct pNew 표. pList ---> pNew
/*
pList->next (*pList).next 하.
*/
pNew->num=2; // struct 표한.
pNew->prev=pList; // pNew struct pList 표. pList <--> pNew
pNew->next=0; // pNew struct 표.
printf("pNew\n");
ShowList(pList);
pIns=(List *)malloc(sizeof(List));
pIns->num=3; // 3 struct 표.
pIns->prev=pList; // pIns pList pNew . (pList <-- pIns)
pIns->next=pNew; // pList <--> pNew, pIns ---> pNew
pList->next=pIns; // pList <--> pIns, pIns ---> pNew, pList <--- pNew (pList <--> pList, pList <--- pNew <--- pIns)
pNew->prev=pIns; // pList <--> pIns, pIns <--> pNew (pList <--> pIns <--> pNew)
printf("pIns\n");
ShowList(pList);
pList->next=pNew; // 해해;;;
pNew->prev=pList;
free(pIns); // malloc함 환한. ( 퓨 . ㅋㅋ)
printf("pIns \n");
ShowList(pList);
free(pNew);
free(pList);
}