我需要一个非常简单的FIFO操作队列: 我已经使用了结构,所以我使用了一些我修改的旧代码用于我的目的:但是现在我的编译器不接受Node作为结构,并且我得到了一些不兼容的指针问题。希望有人看到我失踪的东西:
CODE:
typedef struct _Node {
Node* next;
Task* element;
} Node;
typedef struct _Queue {
Node* head;
} Queue;
Queue* createQueue() {
Queue* q = (Queue*) calloc(1,sizeof(Queue));
return q;
}
void enqueue(Queue* q, Task* task){
Node* newTask = (Node*) calloc(1,sizeof(Node));
newTask->element = task;
Node* root = q->head;
Node* next = root->next;
if (q) {
while(next) {
root = next;
next = root->next;
}
root->next = newTask;
}
}
Task* dequeue(Queue* q) {
Node* root = q->head;
Task* topTask = NULL;
if(q && root) {
topTask = root->element;
q->head = root->next;
free(root);
}
return topTask;
}
错误:
.6:2: error: unknown type name ‘Node’
Node* next;
^
In function ‘enqueue’:
:23:15: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
Node* next = root->next;
^
c:27:9: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
next = root->next;
^
c:29:14: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
root->next = newTask;
^
c: In function ‘dequeue’:
c:38:11: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
q->head = root->next;
提前,
Tim4497