```
#include<stdio.h>\\为什么我在linux里面运行都没有提示段错误在这里却出现了段错误
#include<stdlib.h>
typedef struct node
{
int data;
struct node *next;
}Node;
typedef struct list
{
int nodenum;
Node*first;
Node*last;
}List;
void printf_list(Node *H);
Node *Creat_ListWithHead(List *head,int n);
Node *Merge_list(List *head,List *head1);
Node*ascending_order(List *head);
int main()
{
int x,y;
List *head=(List*)malloc(sizeof(*head));
List *head1=(List*)malloc(sizeof(*head));
head->nodenum=0;
head->first=NULL;
head->last=NULL;
head1->nodenum=0;
head1->first=NULL;
head1->last=NULL;
scanf("%d",&x);
Node *L1=Creat_ListWithHead(head,x);
scanf("%d",&y);
Node *L2=Creat_ListWithHead(head1,y);
L1=Merge_list(head,head1);
Node *L3=ascending_order(head);
printf_list(L3);
return 0;
};
Node *Merge_list(List *head,List *head1)
{
head->last->next=head1->first;
head->last=head1->last;
head->nodenum=(head->nodenum)+(head1->nodenum);
return head->first;
}
Node *Creat_ListWithHead(List *head,int n)
{
Node *pnew=NULL;
while(n--)
{
int d;
scanf("%d",&d);
pnew=(Node *)malloc(sizeof(*pnew));
pnew->data=d;
pnew->next=NULL;
if(head->first==NULL)
{
head->first=pnew;
head->last=pnew;
head->nodenum++;
}
else
{
head->last->next=pnew;
head->last=pnew;
head->nodenum++;
}
}
return head->first;
}
Node *ascending_order(List *head)
{
Node *p=head->first;
int i ,j;
for(j=1;j<(head->nodenum);j++)
{
p=head->first;
for(;p->next!=NULL;p=p->next)
{
if((p->data)>(p->next->data))
{
(p->data)=(p->data)^(p->next->data);
(p->next->data)=(p->data)^(p->next->data);
(p->data)=(p->data)^(p->next->data);
}
}
}
return head->first;
}
void printf_list(Node *H)
{
Node *p=H;
while(p)
{
if(p->next==NULL)
{
printf("%d",p->data);
}
else
{
printf("%d ",p->data);
}
p=p->next;
}
}
```
[ New Thread ]
Problem 3978 >> 段错误 |
201901030309 @ 2022-02-17 22:06:16
|