我正在開發一個迷宮解算器程序,它基本上從文本文件中讀取一個迷宮,從開始點開始,檢查它周圍的所有邊,並移動到空格,標記之前的位置並在找到退出時終止。如何使用泛型類來解決迷宮?
雖然算法本身已經完成,但有些事情我想澄清。該程序需要使用通用類Stack,隊列和座標(存儲當前的x,y座標),我沒有使用它(我使用了Vectors來保存位置)以及其他操作,例如堆棧中的隊列疊加。
這是主要的循環:
if(maz[x][y-1]==' '||maz[x][y-1]=='S'){
if(maz[x][y-1]=='S')
exitfound=true;
maz[x][y]='*';
maz[x][y-1]='@';
y=y-1;
}
如果上述座標它檢查或者是一個開放空間或出口(「S」),如果它是真實的,它移動在那裏,而標記先前位置與一個*和它正在移動到一個'@'的位置。這與其他三方重複。在節目結束時,所有走過的空間都會標有*。但是,我需要使用所述泛型類來操作座標。
這些都是必需的類和對象:
Stack<Coordinate> path = new Stack<Coordinate>(40);
Stack<Queue<Coordinate>> possibilities = new Stack<Queue<Coordinate>>(40);
Coordinate current = new Coordinate(x,y);
Queue<Coordinate> queue = new Queue<Coordinate>(3);
我不明白如何存儲current
對象上的座標,並在類Queue<Coordinate>
的queue
對象插入座標和在棧queue
對象possibilities
對象,來自類Stack<Queue<Coordinate>>
。這是如何完成的?
這was't我的問題。 – Kreator
您是否需要知道如何將項目添加到隊列和堆棧? – screenmutt
如何將座標(即:3,4)添加到類座標,堆棧和隊列中。 – Kreator