public static void PrintElementsBackwards(AbstractDataStructures.Stack <int> elements) { while (elements.Count > 0) { Console.WriteLine(elements.Pop()); } }
private void TryVisitCell(AbstractDataStructures.Stack <Cell> visitedCells, string[,] matrix, Cell cell) { if (this.IsCellAccessible(matrix, cell)) { visitedCells.Push(cell); matrix[cell.X, cell.Y] = cell.Value.ToString(); } }
public static void Main() { #if DEBUG Console.SetIn(new System.IO.StreamReader("../../input.txt")); #endif var numbers = ConsoleUtility.ReadSequenceOfElements <int>(); var elementsBackwards = new AbstractDataStructures.Stack <int>(numbers); // My implementation of Stack PrintElementsBackwards(elementsBackwards); }
public static void Main() { #if DEBUG Console.SetIn(new System.IO.StreamReader("../../input.txt")); #endif var numbers = ConsoleUtility.ReadSequenceOfElements<int>(); var elementsBackwards = new AbstractDataStructures.Stack<int>(numbers); // My implementation of Stack PrintElementsBackwards(elementsBackwards); }
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); }