U E D R , A S I H C RSS

Linked List/숙제

~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);
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:38
Processing time 0.0243 sec