How should I be storing objects that I wish to access in reverse order of the way I placed them in

Posted by andrew hicks on Stack Overflow See other posts from Stack Overflow or by andrew hicks
Published on 2012-09-04T21:30:51Z Indexed on 2012/09/04 21:38 UTC
Read the original article Hit count: 177

Filed under:
|

I'm following this guide here: http://www.mazeworks.com/mazegen/mazetut/index.htm

Or more specficially

create a CellStack (LIFO) to hold a list of cell locations 
set TotalCells = number of cells in grid 
choose a cell at random and call it CurrentCell 
set VisitedCells = 1 

while VisitedCells < TotalCells 

find all neighbors of CurrentCell with all walls intact  
if one or more found 
    choose one at random 
    knock down the wall between it and CurrentCell 
    push CurrentCell location on the CellStack 
    make the new cell CurrentCell 
    add 1 to VisitedCells else 
    pop the most recent cell entry off the CellStack 
    make it CurrentCell endIf 

endWhile

Im writing this in java, My problem is.

How should I be storing my visited cells, So that I can access them from reverse order of when I placed them in.

Like this?

List<Location> visitedCells = new ArrayList<Location>();

Then do I grab with visitedCells.get(visitedCells.size()-1)?

Location stores the x, y and z. Not something Im trying to ask you.

© Stack Overflow or respective owner

Related posts about java

Related posts about maze