danh sách liên kết
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct NODE
{
int Key;
NODE *pNext;
};
NODE* CreateNode(int Data)
{
NODE* pNode;
pNode = new NODE;
if(pNode== NULL)
return NULL;
pNode->Key = Data;
pNode->pNext = NULL;
return pNode;
}
int AddHead(NODE* &pHead, int Data)
{
NODE *pNode;
pNode = CreateNode(Data);
if(pNode==NULL)
return 0;
if(pHead==NULL)
pHead=pNode;
else
{
pNode->pNext=pHead;
pHead=pNode;
}
return 1;
}
void PrintList(NODE *pHead)
{
NODE *pNode;
pNode=pHead;
while(pNode!=NULL)
{
printf("%5d",pNode->Key);
pNode=pNode->pNext; //
}
}
void RemoveAll(NODE* &pHead)
{
NODE *pNode;
while(pHead !=NULL)
{
pNode=pHead;
pHead=pHead->pNext;
delete pNode;
}
pHead=NULL;
}
//int _tmain(int argc, _TCHAR* argv[])
void main()
{
NODE *pRoot;
pRoot=NULL;
int Data;
clrscr();
do
