~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);
}