pta题目段错误 太搞人心态了 看不出来哪里错了
1 #include<stdio.h>
2
struct node{
3
int data;
4
struct node *next;
5
};
6
struct node *create(int n){
7
struct node *head,*tail,p;
8
head=(struct node)malloc(sizeof(struct node));
9
head->next=NULL;
10
tail=head;
11
for(int i=0;i<n;i++){
12
p=(struct node*)malloc(sizeof(struct node));
13
scanf("%d",p->data);
14
p->next=NULL;
15
tail->next=p;
16
tail=p;
17
}
18
return head;
19
}
20
struct node *insert(struct node *L,int x){
21
struct node *head,*p,temp;
22
head=L;
23
temp=(struct node)malloc(sizeof(struct node));
24
temp->data=x;
25
temp->next=NULL;
26
while(L->next!=NULL&&L->next->data<=x){
27
L=L->next;
28
}
29
temp->next=L->next;
30
L->next=temp;
31
return head;
32
}
33
int main(){
34
int repeat;
35
scanf("%d",&repeat);
36
for(int i=0;i<repeat;i++){
37
struct node *head1,*head2,*p;
38
int n;
39
scanf("%d",&n);
40
head1=create(n);
41
int x;
42
scanf("%d",&x);
43
head2=insert(head1,x);
44
printf("size=%d:",n+1);
45
for(p=head2->next;p!=NULL;p=p->next){
46
printf("%d ",p->data);
47
}
48
printf("\n");
49
}
50
return 0;
51
!题目在此