#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int a;
struct Node* pNext;
}Node;
Node* top = NULL;
Node* end = NULL;
void addNode(int a)
{
Node* node = (Node*)malloc (sizeof(Node));
node->pNext = NULL;
node->a = a;
if(top==NULL)
{
top = node;
}
else
{
end->pNext = node;
}
end = node;
}
void delNode(int a)
{
Node *pptop = top;
if(top->a==a)
{
Node* node=top;
top = top->pNext;
free(node);
return;
}
while(pptop->pNext)
{
if(pptop->pNext->a == a)
{
Node* node=pptop->pNext;
pptop->pNext = pptop->pNext->pNext;
free(node);
return;
}
pptop = pptop->pNext;
}
}
Node* findNode(int a)
{
Node* pptop = top;
while(pptop)
{
if(pptop->a==a)
{
return pptop;
}
pptop=pptop->pNext;
}
return NULL;
}
void showNode()
{
Node* pptop = top;
while(pptop)
{
printf("%d\n",pptop->a);
pptop = pptop->pNext;
}
}
int main()
{
int a=3;
while(a--)
{
addNode(a);
}
showNode();
delNode(1);
showNode();
return 0;
}
转载于:https://www.cnblogs.com/D-Rui/p/9769172.html