0
我有一个指针问题。我试图做一个使用链表队列的宽度优先的状态空间搜索,但是我在创建队列(或者将它连接在一起)时遇到了困难。以下是片段:链接列表指针
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没有被分配给任何东西,即使它应该(可能的状态已被找到)。以下
当你使用调试器时,你遇到什么问题? –