0

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

我收到以下错误:

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);
4

2 回答 2

1

尝试像这样引用结构

typedef struct /* my struct tag */ {
int a;
int b;
} MyStructType;

然后

MyStructType * mystruct;
mystruct->a = 34;
// etc...
于 2013-11-07T15:50:27.347 回答
0

linkedListSet应该是struct linkedListSet

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

LinkedListSet应该是linkedListSet

int addItem (struct linkedListSet * setPtr, int info)
于 2013-11-07T15:45:46.660 回答