【发布时间】:2013-10-05 00:27:05
【问题描述】:
我正在 C 中创建一个通用队列,并且收到标题错误。我的 Queue.c 文件中的函数旨在接收初始化的指针。
这是我的结构代码:
struct QueueNode {
struct QueueNode *prev;
struct QueueNode *next;
};
typedef struct QueueNode QNode;
struct Queue {
QNode front;
QNode rear;
};
typedef struct Queue Q;
然后在我的队列初始化函数中,我得到了错误。这是我的功能:
void Q_Init(Q* const pointerQ){
assert (pointerQ != NULL);
pointerQ.front->prev = NULL;
pointerQ.front->next= pointerQ.rear;
pointerQ.rear->prev = pointerQ.front;
pointerQ.rear->prev = NULL;
}
我不完全确定为什么会出现错误。我认为由于 Queue 有 Node 成员而不是指针,我必须使用 pointerQ.front/rear 来访问它们,然后由于 Node 有指针成员,我然后使用 ->next/rear。
任何帮助将不胜感激!
提前致谢!
【问题讨论】:
-
很确定你的节点中应该有某种数据成员。
-
感谢编辑!我会投票,但我确实有足够的代表