#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct node{
int data;
struct node * next;
}ElemSN;
ElemSN * CreatLink(int a[])
{
ElemSN *head, *tail;
head = tail = (ElemSN *)malloc(sizeof(ElemSN));
tail->data = a[0];
tail->next = NULL;
for(int i = 1; i < N; i ++)
{
tail = tail->next = (ElemSN *)malloc(sizeof(ElemSN));
tail->data = a[i];
tail->next = NULL;
}
return head;
}
void PrintLink(ElemSN *head)
{
ElemSN *p;
for(p=head; p; p = p->next)
printf("%5d", p->data);
printf("\n");
}
void DelNode(ElemSN *head)
{
ElemSN *p, *q, *pKey;
pKey = q = head;
p = head->next;
while(p)
{
if(p->data == pKey->data)
{
q->next = p->next;
free(p);
p = q->next;
}
else
{
pKey = p;
q = p;
p = p->next;
}
}
}
int main(void)
{
ElemSN *head;
int a[N] = {2, 2, 4, 4, 5, 6, 6, 9};
head = CreatLink(a);
PrintLink(head);
DelNode(head);
PrintLink(head);
return 0;
}