我试图写一个抽象的数据类型来表示使用链表的整数项集。

我收到以下错误:

ERROR undeclared identifier 'linkedListSet'

error #2152: Unknown field 'code' of '(incomplete) struct LinkedListSet'.


并且觉得我一定在打破一些关于函数,结构和指针的基本规则,但是我真的不明白。下面是我的代码,其中注释了错误消息行。

#include<stdio.h>
#include<stdlib.h>

struct linkedListElement{
    int data;
    struct linkedListElement * next;
};

struct linkedListSet {
    //struct linkedListElement * firstElement;
    struct linkedListElement * header;
    struct linkedListElement * current;
    struct linkedListElement * temp;
    int code;
};

struct linkedListSet * createdSet (){
    struct linkedListSet * newSet = malloc(sizeof(linkedListSet));
    //ERROR undeclared identifier 'linkedListSet'

    newSet->header->data = 0;
    newSet->header->next = NULL;

    return newSet;
}

int addItem (struct LinkedListSet * setPtr, int info){
    struct linkedListElement * newElementPtr;

    setPtr->code = 3;
    //error #2152: Unknown field 'code' of '(incomplete) struct LinkedListSet'.
    return 1;
};

int main(){
    return (0);

最佳答案

linkedListSet应为struct linkedListSet

struct linkedListSet * newSet = malloc(sizeof(struct linkedListSet));


LinkedListSet应该是linkedListSet

int addItem (struct linkedListSet * setPtr, int info)

关于c - C套链表(抽象数据类型),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19840070/

10-11 21:19