大佬教程收集整理的这篇文章主要介绍了c – 链接列表数组,移动到下一个节点错误;,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
struct node{ int LOCATIOn; struct node *next; struct node *prevIoUs; }; typedef struct ListHeader{ nodeType *first; nodeType *current; nodeType *last; } ListHeader; struct adjList{ ListHeader *header; int size; }; struct List{ adjListType *list; int size; }; ListType newList(int numVerts){ ListType new = malloc(sizeof(struct List)); new->list = calloc(numVerts,sizeof(adjListTypE)); new->size = numVerts; int i; for(i = 0; i <= numVerts; i++){ new->list[i] = newAdjList(); } return new; } adjListType newAdjList(void){ adjListType new = malloc(sizeof(struct adjList)); new->header = malloc(sizeof(ListHeader)); new->header->first = NULL; new->header->current = NULL; new->header->last = NULL; new->size = 0; return new; } nodeType newNode(int LOCATIOn){ nodeType new = malloc(sizeof(struct nodE)); new->LOCATIOn = LOCATIOn; return new; }
当我尝试使用此代码移动到链接列表中的下@L_262_0@节点时,它会给我@L_262_0@错误
(ListType l,int LOCATIOn)
l->list[LOCATIOn]->header->current = l->list[LOCATIOn]->header->current->next;
这是我得到的错误:
成员引用基类型’nodeType'(又名’struct node *’)不是结构或联合
struct List{ adjListType list[10]; int size; };
当然你也可以使用Pointer,但是你需要向我们展示你如何使用calloc为它分配数组内存?
ListType newList(int numVerts){ ListType new = malloc(sizeof(struct List)); new->list = calloc(numVerts,sizeof(struct adjListTypE));//Here you missed struct new->size = numVerts; int i; for(i = 0; i < numVerts; i++){ // Here <= instead of < for 10 length array is 0 to 9 new->list[i] = newAdjList(); } return new; }
此外,您可能希望返回& new作为参考,或者您最终将创建不必要的副本…
我要去你的代码,如果我发现了其他任何内容,我会更新这个答案..同时如果你能告诉我们你得到了什么错误会很好吗?
同样在您显示的代码中,您将设置next,prev和current为NULL,但是您要更改这些值…否则您将继续获取NULL POINTER EXCEPTION
以上是大佬教程为你收集整理的c – 链接列表数组,移动到下一个节点错误;全部内容,希望文章能够帮你解决c – 链接列表数组,移动到下一个节点错误;所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。