#include <stdio.h>
#include <stdlib.h>
typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node {
ElementType Data;
PtrToNode Next;
};
typedef PtrToNode List;
List Read();
void Print( List L );
List Insert( List L);
int main()
{
List L;
ElementType X;
L = Read();
L = Insert(L);
Print(L);
return 0;
}
List Read()
{
ElementType i,n;
List head,p,q;
head=(List)malloc(sizeof(struct Node));
head->Next=NULL;
q=head;
printf(“请输入要创建的元素个数,非递减形式输入\n”);
scanf("%d",&n);
for(i=0;i<n;i++)
{
p=(List)malloc(sizeof(struct Node));
scanf("%d",&p->Data);
p->Next=q->Next;
q->Next=p;
q=p;
}
return(head);
}
void Print( List L )
{
List p;
p=L->Next;
while(p!=NULL)
{
printf(" %d",p->Data);
p=p->Next;
}
}
List Insert( List L)
{
ElementType k=0,pd,pd1;
List q,p,t;
q = L->Next;
while(q!=NULL)
{
pd = 1;
p = q->Next;
k = q->Data;
if(p!=NULL)
{
if(p->Data == k)
{
while(1)
{
p = p->Next;
if(p == NULL)
break;
if(p->Data!=k)
break;
}
q->Next = p;
q = p;
pd = 0;
}
}
if(pd)
q = q->Next;
}
return(L);
}