View Code of Problem 83

# include<stdio.h>
# include<stdlib.h>
struct node{
	int num;
	int score;
	struct node *next;
};
int main(){
	int M,N;
	scanf("%d %d",&M,&N);
	node*L=(node*)malloc(sizeof(node));
	L->next=NULL;
	node*pre=NULL,*p=NULL;
	for(int i=1;i<=M+N;i++){
		node*s=(node*)malloc(sizeof(node));
		scanf("%d %d",&s->num,&s->score);
		pre=L;
		if(pre->next==NULL){
			pre->next=s;
            s->next=NULL;
		}
		else{
			while(pre->next!=NULL&&(s->num)> (pre->next->num)){
				pre=pre->next;
			}
		    s->next=pre->next;
		    pre->next=s;
		}
	}
	L=L->next;
	while(L!=NULL){
	 p=L;
	 L=L->next;
	 printf("%d %d\n",p->num,p->score);
	 free(p);
	} 
   return 0;
}
/*
Main.c: In function 'main':
Main.c:11:2: error: unknown type name 'node'
  node*L=(node*)malloc(sizeof(node));
  ^
Main.c:11:10: error: 'node' undeclared (first use in this function)
  node*L=(node*)malloc(sizeof(node));
          ^
Main.c:11:10: note: each undeclared identifier is reported only once for each function it appears in
Main.c:11:15: error: expected expression before ')' token
  node*L=(node*)malloc(sizeof(node));
               ^
Main.c:12:3: error: request for member 'next' in something not a structure or union
  L->next=NULL;
   ^
Main.c:13:7: error: 'pre' undeclared (first use in this function)
  node*pre=NULL,*p=NULL;
       ^
Main.c:13:17: error: 'p' undeclared (first use in this function)
  node*pre=NULL,*p=NULL;
                 ^
Main.c:13:15: warning: left-hand operand of comma expression has no effect [-Wunused-value]
  node*pre=NULL,*p=NULL;
               ^
Main.c:15:8: error: 's' undeclared (first use in this function)
   node*s=(node*)malloc(sizeof(node));
        ^
Main.c:15:16: error: expected expression before ')' token
   node*s=(node*)malloc(sizeof(node));
                ^
Main.c:30:5: error: request for member 'next' in something not a structure or union
  L=L->next;
     ^
Main.c:33:6: error: request for member 'next' in something not a structure or union
   L=L->next;
      ^
*/

Double click to view unformatted code.


Back to problem 83