Stack to --> ArrayList Java
我做了一个Stack和一个ArrayList来做研究。实际上,我现在想让我的堆栈被ArrayList取代,但是如何将堆栈转换为ArrayList?它是如何与推,流行...?
谢谢
public static ArrayList<State> search(State finalstate)
{
ArrayList<State> toreturn = new ArrayList<State>();
Stack<State>mystack=new Stack<State>();
mystack.push(initState);
State currState;
currState=initState;
while(!mystack.isEmpty() && !currState.equals(finalstate) )
{
currState=mystack.pop();
toreturn.add(currState);
if(currState.vecinos.containsKey("up"))
{
mystack.push(currState).vecinos.get("up");
}
if(currState.vecinos.containsKey("down"))
{
mystack.push(currState).vecinos.get("down");
}
if(currState.vecinos.containsKey("left"))
{
mystack.push(currState).vecinos.get("left");
}
if(currState.vecinos.containsKey("right"))
{
mystack.push(currState).vecinos.get("right");
}
}
return toreturn;
}