Used a stack to access to the empty cells.