|
![]() | 作者: NewDemon [lion1985]
![]() |
登录 |
还是遇到说函数声明错误啊,附源: typedef struct LNODE {int date; struct LNODE *priou; struct LNODE *next; }LNODE,linklist; Linklist creat(Linklist L) {int node,k,b;Linklist p; L=(Linklist)malloc(sizeof(LNODE));L->date=-1; L->next=NULL;L->priou=NULL;b=k=0 printf("\n Please input the node (end with 0):\n"); scanf("%d",&node) while(node!=0) {p=(Linklist)malloc(sizeof(LNODE));p->date=node; p->next=NULL;p->priou=L;L->next=p; p->date=node;L=L->next;k++;b++; printf("\n Please input the node (end with 0):\n"); scanf("%d",&node);} return L; } Linklist insert(Linklist L,int i,int x) {int j;Linklist p,s; while(i<0||i>k+1) printf("\n ERROR position!\n"); while(k>i) {L=L->priou;} else {s=(Linklist)malloc(sizeof(LNODE)); s->priou=L->priou;s->next=L;s->priou->next=s;L->priou=s;} return L;} Linklist delete(Linklist L,int i) {int i,k;Linklist p; while(i>b+1||i<0) printf("\n ERROR position!\n"); while(i!=k) {if(i>k) {L=L->next,k++} else {l=L->priou,k--}} L->priou->next=L->next; L->next->priou=L->priou; printf("\n The delete date is :%d\n",L->date); free(L); } void display(Linklist L) {Listlist p; p=la->next; while(p!=NULL) {printf("%d",p->date);p=p->next;} printf("\n");} main() {Linklist L;int i, x; L=creat(L); display(L); printf("\n Please input the position you want to insert;"); scanf("%d",&i); printf("\n Please input the node you want to insert:"); scanf("%d",&x); L=insert(L,i,x); display(L); printf("\n Please input the node position you want to delete:") scanf("%d",&i); L=delete(L,i); display(L); } ![]() ![]() ![]() ![]() |
地主 发表时间: 06-04-10 14:34 |
![]() | 回复: NetMelody [mmgg00] ![]() |
登录 |
你的函数定义成这样Linklist creat(Linklist L) 而在函数中最后又是 return L; 你的 L 又是 L=(Linklist)malloc(sizeof(LNODE)); 仔细想想吧 |
B1层 发表时间: 06-04-10 16:07 |
![]() | 回复: NewDemon [lion1985] ![]() |
登录 |
L 是我定义的Linklist类型里的啊. 有什么问题? ![]() ![]() [此贴被 NewDemon(lion1985) 在 04月10日18时20分 编辑过] |
B2层 发表时间: 06-04-10 18:18 |
![]() | 回复: void [void] ![]() |
登录 |
看了个开头发现 typedef struct LNODE {int date; struct LNODE *priou; struct LNODE *next; }LNODE,linklist; Linklist creat(Linklist L) Linklist里的L怎么是大写,你上面明明是小写嘛~ 你等于拿Int来定义整形,兄弟仔细点嘛~ |
B3层 发表时间: 06-04-10 20:24 |
![]() | 回复: NewDemon [lion1985] ![]() |
登录 |
大小写改了,呵呵,谢谢,再看了程序,错误好多好多.哈哈,继续改ING![]() ![]() |
B4层 发表时间: 06-04-10 20:41 |
![]() | 回复: void [void] ![]() |
登录 |
还有个就是关于->的使用~这只是在定义了struct类型的指针变量对成员分量进行操作时才用->的,可你的L并不是指针,只是一个struct类型的变量而已~所以应该用 . 操作符 (说得不对的地方请高手指正,我学这个也不是很久,谢谢!) |
B5层 发表时间: 06-04-10 20:48 |
![]() | 回复: NetMelody [mmgg00] ![]() |
登录 |
L=(Linklist)malloc(sizeof(LNODE)) malloc返回指针,那么L就应该是指针才对 |
B6层 发表时间: 06-04-11 09:17 |
![]() | 回复: NewDemon [lion1985] ![]() |
登录 |
自己写的程序看了自己也迷茫![]() ![]() |
B7层 发表时间: 06-04-11 09:32 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号