Exemple #1
0
 public static void PrintElementsBackwards(AbstractDataStructures.Stack <int> elements)
 {
     while (elements.Count > 0)
     {
         Console.WriteLine(elements.Pop());
     }
 }
        public string[,] FindAllPaths(string[,] matrix)
        {
            var startupCell = this.GetStartupCell(matrix);

            var visitedCells = new AbstractDataStructures.Stack<Cell>(); // My implementation of Stack
            visitedCells.Push(startupCell);

            while (visitedCells.Count > 0)
            {
                var currentCell = visitedCells.Pop();
                int x = currentCell.X, y = currentCell.Y, nextValue = currentCell.Value + 1;

                this.TryVisitCell(visitedCells, matrix, new Cell(x, y + 1, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x, y - 1, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x + 1, y, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x - 1, y, nextValue));
            }

            this.MarkInaccessibleCells(matrix);

            return matrix;
        }
        public string[,] FindAllPaths(string[,] matrix)
        {
            var startupCell = this.GetStartupCell(matrix);

            var visitedCells = new AbstractDataStructures.Stack <Cell>(); // My implementation of Stack

            visitedCells.Push(startupCell);

            while (visitedCells.Count > 0)
            {
                var currentCell = visitedCells.Pop();
                int x = currentCell.X, y = currentCell.Y, nextValue = currentCell.Value + 1;

                this.TryVisitCell(visitedCells, matrix, new Cell(x, y + 1, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x, y - 1, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x + 1, y, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x - 1, y, nextValue));
            }

            this.MarkInaccessibleCells(matrix);

            return(matrix);
        }