我的指针有问题。我正在尝试使用链表队列进行广度优先状态空间搜索,但我无法创建队列(或者更确切地说将它链接在一起)。这是片段:
typedef struct queueList {
STATE *state;
queueList *next;
queueList(STATE *state): state(state), next(NULL) {}
~queueList() {delete next;}
} QUEUE_ELEMENT;
void moveAround(STATE *start) {
QUEUE_ELEMENT *queueBegin = new QUEUE_ELEMENT(start);
QUEUE_ELEMENT *queueEnd;
queueBegin->next = queueEnd;
while (queueBegin != NULL) {
STATE *current = queueBegin->state;
if (compareStates(current,finish) == 1) {
answer = current;
return;
}
for (int i = 0; i < 12; i++) {
STATE *newState = expandState(current, i);
if (newState != NULL) {
queueEnd = new QUEUE_ELEMENT(newState);
queueEnd = queueEnd->next;
}
}
queueBegin = queueBegin->next;
}
}
什么地方出了错?queueBegin->next 没有被分配给任何东西,即使它应该(已找到可能的状态)。