想问一下为什么会出现3221225477?(题目要求输入两个非降序链表输出并集)

[复制链接]
查看11 | 回复0 | 2023-4-8 23:00:27 | 显示全部楼层 |阅读模式
#include
#include
#includetypedef struct list{

int deta;

struct list *next;
}node,*link;link delete_node(link pointer,link tmp){

if(tmp==NULL) return pointer->next;

else{

if(tmp->next->next==NULL) tmp->next=NULL;

else tmp->next=tmp->next->next;

return pointer;

}
}void selection_minode(link pointer,int num){

link tmp,btmp;

int i,min,cnt=num;

if(num==0)printf("NULL");

else if(num==1){

min=pointer->deta;

printf("%d",min);

}

else{



for(i=1;ideta;

btmp=NULL;

while(tmp->next){

if(min>tmp->next->deta){

min=tmp->next->deta;

btmp=tmp;

}

tmp=tmp->next;

}

printf("%d ",min);

pointer=delete_node(pointer,btmp);

}

min=pointer->deta;

printf("%d",min);

}


}link create_list(){

link tmp1,tmp2,pointer;

int i;

pointer=(link)malloc(sizeof(node));

scanf("%d",&i);

tmp1=pointer;

if(i==-1){

tmp1=NULL;

}

else {

tmp1->deta=i;

tmp1->next=NULL;

scanf("%d",&i);

}

while(i!=-1){

tmp2=(link)malloc(sizeof(node));

tmp2->next=NULL;

tmp2->deta=i;

tmp1->next=tmp2;

tmp1=tmp1->next;

scanf("%d",&i);

}

return pointer;
}link concatenate(link pointer1,link pointer2){

link tmp;

tmp=pointer1;

while(tmp->next) tmp=tmp->next;

tmp->next=pointer2;

return pointer1;
}int count(link ptr){

int i=0;

while(ptr->deta){

i++;

ptr=ptr->next;


}

return i;
}int main(){

link ptr1,ptr2;

int num;

ptr1=create_list();

ptr2=create_list();

concatenate(ptr1,ptr2);

num=count(ptr1);

selection_minode(ptr1,num);

return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行