//单向链表 赋值和动态分配内存
#include "stdafx.h"
#include <stdlib.h>
struct Node
{
int iData;
struct Node *pNext;
};
void Func(struct Node * pHead)
{
int i=1;
while(pHead)
{
pHead->iData=i++;
pHead=pHead->pNext;
}
}
void Free(struct Node * pHead)
{
struct Node * pDelete;
while(pHead)
{
pDelete=pHead;
pHead=pHead->pNext;
free(pDelete);
}
}
int main(int argc, char* argv[])
{
// struct Node *pHead,node,node2,node3;
// pHead=&node;
// node.pNext=&node2;
// node2.pNext=&node3;
// node3.pNext=NULL;
// Func(pHead);
Node *pHead;
pHead=(struct Node *)malloc(sizeof(struct Node));
pHead->pNext=(struct Node *)malloc(sizeof(struct Node));
pHead->pNext->pNext=(struct Node *)malloc(sizeof(struct Node));
pHead->pNext->pNext->pNext=(struct Node *)malloc(sizeof(struct Node));
pHead->pNext->pNext->pNext=NULL;
Free(pHead);
return 0;
}