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沒有被分配給任何東西,即使它應該(可能的狀態已被找到)。以下
當你使用調試器時,你遇到什麼問題? –