【发布时间】:2022-11-22 02:01:58
【问题描述】:
我正在尝试使用以下逻辑为 Java 游戏创建一个循环:
if (the stack is not empty) {
pop top move from stack.
reset the board.
}
// then i create a while loop to pop the moves back onto the board.
while(stack is not empty) {
type userMove = history.pop();
assign userMove back onto the board.
}
我坚持的最后一点也是将我正在分配的用户移动推回到堆栈中。
如果我这样做:
while(stack is not empty) {
type userMove = history.pop();
assign userMove back onto the board.
history.push(userMove);
}
然后我将创建一个无限循环。所以我不确定如何做最后一步将这些动作推回到堆栈中。
【问题讨论】: