#include<stdio.h>
#include<malloc.h>
#define NULL 0
struct node
{ int data ;
struct node *next;
};
struct node *createlink(int n)
{ struct node *head,*p,*q;
int i,a;
head=(struct node *)malloc(sizeof(struct node *));
p=q=head;
for(i=0;i<n;i++)
{ p=(struct node *)malloc(sizeof(struct node *));
scanf("%d",&a);
p->data=a;
q->next=p;
q=p;
}
p->next=NULL;
return head;
}
int length(struct node *head )
{ struct node *p;
int count=0;
p=head->next;
while(p!=NULL)
{ count++;
p=p->next;
}
return count;
}
struct node *insert(int length,struct node *head)
{struct node *r,*p,*q;
int j,x,a,b;
p=head;
while(p->next!=NULL)
{for(j=0;j<length-1;j++)
{p=p->next;
q=p->next;
if((p->data-q->data)>1)
{x=p->data-q->data;
for(j=0;j<x-1;j++)
{r=(struct node *)malloc(sizeof(struct node));
a=p->data;
r->data=a-1;
r->next=p->next;
p->next=r;
p=r;
}
}
if((q->data-p->data)>1)
{x=q->data-p->data;
for(j=0;j<x-1;j++)
{r=(struct node *)malloc(sizeof(struct node));
p->data=b;
r->data=b-1;
r->next=p->next;
p->next=r;
p=r;
}
}
}
}
return head;
}
print(struct node *head)
{ struct node *p;
p=head->next;
while(p!=NULL)
{printf("->%d",p->data);
p=p->next;
}
}
main()
{ struct node *head,*p;
int n,a;
scanf("%d",&n);
head=createlink(n);
print(head);
a=length(head);
p=insert(a,head);
print(p);
}
把链表中的数据按等差为1填充 如1->3->8->5 变为1->2->3->4->5->6->7->8->7->6->5