#include<stdio.h>
#define INIT() (Node*)malloc(sizeof(Node))
typedef struct node{ //带头结点的链表
int data;
struct node* next;
}Node,*List;
List Init(){ //创建空链表,返回头节点
Node* head=(Node*)malloc(sizeof(Node));
head->data=0;
head->next=NULL;
return head;
}
void Insert(List head,int val){ //插入节点
Node* cur=head;
while(cur->next) cur=cur->next;
Node* p=INIT();
p->data=val;
p->next=NULL;
cur->next=p;
head->data++;
}
void Add(List head,int i){
Node *cur=head->next;
int n=1;
for(n;n<i;n++) cur=cur->next;
Node* node=INIT();
node->data=i; node->next=cur->next;
cur->next=node;
}
int main(){
int n,a,i;
scanf("%d%d",&n,&i);
List head=Init();
for(int i=0;i<n;i++){
scanf("%d",&a);
Insert(head,a);
}
Add(head,i);
Node* cur=head->next;
while(cur){
printf("%d ",cur->data);
cur=cur->next;
}
return 0;
}
没写出来不知道问题出在哪里了就是插入到后面

京公网安备 11010502036488号