#include <stdio.h>
#include <malloc.h>
#include<string.h>
typedef struct _STU
{
int num;
char name[20];
_STU(int n, char nm[])
{
num = n;
strcpy(name, nm);
}
}STU;
typedef struct _NODE
{
STU s;
struct _NODE *next;
}NODE, *PNODE;
void InsertHead(PNODE *ppHead, STU s)
{
PNODE PNew = (PNODE)malloc(sizeof(NODE));
PNew->s = s;
PNew->next = *ppHead;
*ppHead = PNew;
}
void DeleteHead(PNODE *ppHead)
{
PNODE pos = *ppHead;
if (*ppHead !=NULL)
{
*ppHead = pos->next;
free(pos);
pos = NULL;
}
}
PNODE FirstDeleteBynum(PNODE pHead, int num)
{
PNODE pos;
pos = pHead;
while (pos->next != NULL && pos->next->s.num != num)
{
pos = pos->next;
}
if (pos->next != NULL)
{
PNODE t = pos->next;
pos->next = t->next;
free(t);
t = NULL;
return pos;
}
else
{
return NULL;
}
}
void DeleteBynum(PNODE *ppHead, int num)
{
while (*ppHead != NULL && (*ppHead)->s.num == num)
{
DeleteHead(ppHead);
}
PNODE pos = *ppHead;
pos = FirstDeleteBynum(pos, num);
while (pos != NULL)
{
pos = FirstDeleteBynum(pos, num);
}
}
void Clear(PNODE * ppHead)
{
while (*ppHead != NULL)
{
DeleteHead(ppHead);
}
}
void Show(const PNODE *ppHead)
{
PNODE pos = *ppHead;
while (pos != NULL)
{
printf("%d,%s\n", pos->s.num, pos->s.name);
pos = pos->next;
}
printf("\b;");
}
void main()
{
PNODE head = NULL;
PNODE head1 = NULL;
InsertHead(&head, _STU(1001, " 徐子平"));
InsertHead(&head, _STU(1002, " 兴隆"));
InsertHead(&head, _STU(1003, " 路夏"));
InsertHead(&head, _STU(1004, " 穆司阳"));
InsertHead(&head, _STU(1005, " 卓治"));
InsertHead(&head, _STU(1006, " 池大勇"));
InsertHead(&head, _STU(1007, “严智明”));
InsertHead(&head1, _STU(1001, "卓宇"));
InsertHead(&head1, _STU(1002, " 关岳"));
InsertHead(&head1, _STU(1006, " 佳乐"));
PNODE pos = head1;
while (pos != NULL)
{
DeleteBynum(&head, pos->s.num);
pos = pos->next;
}
Show(&head);
Clear(&head);
}