单链表的创建与遍历

#include "stdafx.h"
#include <malloc.h>


typedef struct NODE 
{
    int data;
    struct NODE* pNext;

}NODE,*PNODE;
PNODE Create_list(void);
void Traversal_list(PNODE pHead);

int _tmain(int argc, _TCHAR* argv[])
{

    PNODE pHead = NULL;
    pHead = Create_list();
    Traversal_list(pHead);
    getchar();
    return 0;
}
PNODE Create_list(void)
{
    int i;
    int num[10] = {1,2,3,4,5,6,7,8,9,10};
    PNODE pHead = (PNODE)malloc(sizeof(struct NODE));
    PNODE p = pHead;
    p->pNext = NULL;
    for (i=0;i<10;i++)
    {
        PNODE pNew = (PNODE)malloc(sizeof(struct NODE));

        pNew->data = num[i];
        p->pNext = pNew;
        pNew->pNext = NULL;
        p=pNew;
    }
    return pHead;
}
void Traversal_list(PNODE pHead)
{
    PNODE p = pHead->pNext;
    while(p)
    {
        printf("%d  ",p->data);
        p = p->pNext;
    }
    return;
}
原文地址:https://www.cnblogs.com/wumac/p/4124962.html