#include<stdio.h> #include<stdlib.h> typedef struct LNode{ int id; int grade; struct LNode *next; }LNode,*LinkList; LinkList CreatList(LinkList &L,int n) //不是很明白这个 LinkList &L,还有main函数调用需不需要给链表的头指针呢?????? { LNode *s,*r=L;int x,y; L=(LinkList)malloc(sizeof(LNode)); L->next=NULL; while(n>0) { scanf("%d %d",&x,&y); //x是id,y是grade; s=(LNode*)malloc(sizeof(LNode)); s->id=x; s->grade=y; r->next=s; r=s; n--; } r->next=NULL; return L; } void Sort(LinkList &L) { LNode *p=L->next,*pre; LNode *r=p->next; p->next=NULL; p=r; while(p!=NULL) { r=p->next; pre=L; while(pre->next!=NULL&&pre->next->id<p->id) pre=pre->next; p->next=pre->next; pre->next=p; p=r; } } LinkList Merge(LinkList &a,LinkList &b) { LNode *p=a; while(p->next) { p=p->next; } p->next=b; free(b); return a; } void Print_a(LinkList &a) { LNode *p=a; while(p->next) { printf("%d %d\n",p->id,p->grade); } } int main() { LinkList a,b; int n,m; scanf("%d %d",&n,&m); CreatList(a,n); CreatList(b,m); a=Merge(a,b); Sort(a); Print_a(a); return 0; } /* Main.c:8:29: error: expected ';', ',' or ')' before '&' token LinkList CreatList(LinkList &L,int n) //不是很明白这个 LinkList &L,还有main函数调用需不需要给链表的头指针呢?????? ^ Main.c:26:20: error: expected ';', ',' or ')' before '&' token void Sort(LinkList &L) ^ Main.c:42:25: error: expected ';', ',' or ')' before '&' token LinkList Merge(LinkList &a,LinkList &b) ^ Main.c:53:23: error: expected ';', ',' or ')' before '&' token void Print_a(LinkList &a) ^ Main.c: In function 'main': Main.c:66:2: warning: implicit declaration of function 'CreatList' [-Wimplicit-function-declaration] CreatList(a,n); ^ Main.c:68:2: warning: implicit declaration of function 'Merge' [-Wimplicit-function-declaration] a=Merge(a,b); ^ Main.c:68:3: warning: assignment makes pointer from integer without a cast a=Merge(a,b); ^ Main.c:69:2: warning: implicit declaration of function 'Sort' [-Wimplicit-function-declaration] Sort(a); ^ Main.c:70:2: warning: implicit declaration of function 'Print_a' [-Wimplicit-function-declaration] Print_a(a); ^ */ |
Double click to view unformatted code.