#include <stdlib.h>
#include <stdio.h>
typedef struct tagLinkList
{
int data;
tagLinkList * pNext;
}LL,*LPLL;
void AddNode(LPLL pHead,int data)
{
//将节点插入到头节点的后一个位置
LPLL pNode = (LPLL)malloc(sizeof(LL));
pNode->data = data;
pNode->pNext = pHead->pNext;
pHead->pNext = pNode;
}
void Display(LPLL pHead)
{
LPLL pNode = pHead->pNext;
while(pHead != pNode)
{
printf("%d,",pNode->data);
pNode = pNode->pNext;
}
}
void DestoryList(LPLL pHead)
{
LPLL pNode = pHead->pNext;
while(pHead != pNode)
{
LPLL pNext = pNode->pNext;
free(pNode);
pNode = pNext;
}
}
int main()
{
LL head;
head.data = 0;
//头节点的next节点 = 自己,就构筑了循环链表。
head.pNext = &head;
for(int i = 1 ; i <= 10 ; i ++)
{
AddNode(&head,i);
}
Display(&head);
DestoryList(&head);
return 0;
}
|