#include <stdio.h> #include <malloc.h> typedef struct node{ int id; int grade; struct node *next; }NODE; NODE *creat(int n){ node *head,*p,*q; head = (struct node*)malloc(sizeof(struct node)); head->next = NULL; while(n>0){ p = (struct node*)malloc(sizeof(struct node)); scanf("%d%d",&p->id,&p->grade); if(head->next == NULL){ p->next = head->next; head->next = p; q = p; } else{ p->next = q->next; q->next = p; q = p; } n--; } return head; } NODE *merge(NODE *head,NODE *head1){ NODE *p; p = head; while(p->next!=NULL) p = p->next; p->next = head1->next; head1->next = NULL; return head; } int sort(NODE *head,int n){ NODE *p; int id,grade; while(n>0){ for(p = head->next;p->next!=NULL;p=p->next){ if(p->grade > p->next->grade){ grade = p->grade; id=p->id; p->grade = p->next->grade; p->id = p->next->id; p->next->grade = grade; p->next->id = id; } } n--; } p = head->next; while(p!=NULL){ printf("%d %d\n",p->id,p->grade); p = p->next; } return 0; } main(){ NODE *head,*head1; int n,m; scanf("%d%d",&n,&m); head = creat(n); head1 = creat(m); head = merge(head,head1); sort(head,n+m); return 0; } /* Main.c: In function 'creat': Main.c:9:2: error: unknown type name 'node' node *head,*p,*q; ^ Main.c:10:7: warning: assignment from incompatible pointer type head = (struct node*)malloc(sizeof(struct node)); ^ Main.c:11:6: error: request for member 'next' in something not a structure or union head->next = NULL; ^ Main.c:13:5: warning: assignment from incompatible pointer type p = (struct node*)malloc(sizeof(struct node)); ^ Main.c:14:18: error: request for member 'id' in something not a structure or union scanf("%d%d",&p->id,&p->grade); ^ Main.c:14:25: error: request for member 'grade' in something not a structure or union scanf("%d%d",&p->id,&p->grade); ^ Main.c:15:10: error: request for member 'next' in something not a structure or union if(head->next == NULL){ ^ Main.c:16:5: error: request for member 'next' in something not a structure or union p->next = head->next; ^ Main.c:16:18: error: request for member 'next' in something not a structure or union p->next = head->next; ^ Main.c:17:8: error: request for member 'next' in something not a structure or union head->next = p; ^ Main.c:21:5: error: request for member 'next' in something not a structure or union p->next = q->next; ^ Main.c:21:15: error: request for member 'next' in something not a structure or union p->next = q->next; ^ Main.c:22:5: error: request for member 'next' in something not a structure or union q->next = p; ^ Main.c:27:2: warning: return from incompatible pointer type return head; ^ Main.c: At top level: Main.c:61:1: warning: return type defaults to 'int' main(){ ^ */ |
Double click to view unformatted code.