有没有大神告诉我这代码出啥问题了
c语言吧
全部回复
仅看楼主
level 1
po900 楼主
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
typedef struct node
{
int num;
int score;
struct node *next;
}Node;
Node *creatNode(int num,int score)
{
Node *newNode=(Node*)malloc(sizeof(Node));
newNode->num=num;
newNode->score=score;
newNode->next=NULL;
return newNode;
}
Node *insertNode(Node *head,Node *newNode)
{
if(head==NULL)
{
return newNode;
}
if(head->num>newNode->num)
{
newNode->next=head;
return newNode;
}
Node *current=head;
while(current->next!=NULL&¤t->next->num<=newNode->num)
{
current=current->next;
}
newNode->next=current->next;
current->next=newNode;
return head;
}
void print(Node *head)
{
while(head!=NULL)
{
cout<<head->num<<endl;
cout<<head->score<<endl;
head=head->next;
}
}
2023年03月23日 10点03分 1
level 1
po900 楼主
int main()
{
int n,m,num,score;
Node *listA=NULL;
Node *listB=NULL;
cin>>n;
cin>>m;
/*A*/
for(int i=0;i<n;i++)
{
scanf("%d %d",&num,&score);
Node *newNode=creatNode(num,score);
insertNode(listA,newNode);
}
/*B*/
for(int i=0;i<m;i++)
{
scanf("%d %d",&num,&score);
Node *newNode=creatNode(num,score);
insertNode(listB,newNode);
}
/*ºÏ²¢*/
while(listB)
{
listA=insertNode(listA,creatNode(listB->num, listB->score));
listB=listB->next;
}
print(listA);
return 0;
}
2023年03月23日 10点03分 2
level 1
po900 楼主
阿里嘎多!
2023年03月23日 10点03分 3
level 1
po900 楼主
@全体成员[花心][花心]
2023年03月23日 10点03分 4
level 7
有报错截图吗,优先发报错截图
2023年03月23日 23点03分 5
1