Advertisement
Infiniti_Inter

22-1 Ok

May 6th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7.  
  8. public class Graph
  9. {
  10.  
  11. public string[] f;
  12.  
  13. private class Node //вложенный класс для скрытия данных и алгоритмов
  14. {
  15. public void Show()
  16. {
  17. for (int i = 0; i < array.GetLength(0); ++i)
  18. {
  19. for (int j = 0; j < array.GetLength(0); ++j)
  20. Console.Write(array[i, j] + " ");
  21. Console.WriteLine();
  22. }
  23. }
  24. public void ExcludeNode(int k)
  25. {
  26. for (int i = 0; i < array.GetLength(0); ++i)
  27. array[i, k] = array[k, i] = 0;
  28.  
  29. }
  30. private int[,] array; //матрица смежности
  31. public int this[int i, int j] //индексатор для обращения к матрице смежности
  32. {
  33. get
  34. {
  35. return array[i, j];
  36. }
  37. set
  38. {
  39. array[i, j] = value;
  40. }
  41. }
  42. public bool this[int i] //индексатор для обращения к матрице меток
  43. {
  44. get
  45. {
  46. return nov[i];
  47. }
  48. set
  49. {
  50. nov[i] = value;
  51. }
  52. }
  53. public int Size //свойство для получения размерности матрицы смежности
  54. {
  55. get
  56. {
  57. return array.GetLength(0);
  58. }
  59. }
  60. private bool[] nov; //вспомогательный массив: если i-ый элемент массива равен
  61. //true, то i-ая вершина еще не просмотрена; если i-ый
  62. //элемент равен false, то i-ая вершина просмотрена
  63. public void NovSet() //метод помечает все вершины графа как непросмотреные
  64. {
  65. for (int i = 0; i < Size; i++)
  66. {
  67. nov[i] = true;
  68. }
  69. }
  70. //конструктор вложенного класса, инициализирует матрицу смежности и
  71. // вспомогательный массив
  72. public Node(int[,] a)
  73. {
  74. array = a;
  75. nov = new bool[a.GetLength(0)];
  76. }
  77.  
  78.  
  79.  
  80.  
  81. }
  82. private Node graph; //закрытое поле, реализующее АТД «граф»
  83.  
  84.  
  85. public Graph(string name) //конструктор внешнего класса
  86. {
  87. using (StreamReader file = new StreamReader($"{name}"))
  88. {
  89. int n = int.Parse(file.ReadLine());
  90. int[,] a = new int[n, n];
  91.  
  92.  
  93. for (int i = 0; i < n; i++)
  94. {
  95. string line = file.ReadLine();
  96. string[] mas = line.Split(' ');
  97. for (int j = 0; j < n; j++)
  98. {
  99. a[i, j] = int.Parse(mas[j]);
  100. }
  101. }
  102. graph = new Node(a);
  103. }
  104. }
  105. //метод выводит матрицу смежности на консольное окно
  106. public void Show()
  107. {
  108. graph.Show();
  109. }
  110.  
  111.  
  112.  
  113. public void ExcludeNode(int k)
  114. {
  115. graph.ExcludeNode(k);
  116. }
  117.  
  118.  
  119. public int GetLength()
  120. {
  121. return graph.Size;
  122. }
  123. }
  124. class Program
  125. {
  126. static void Main(string[] args)
  127. {
  128.  
  129. Graph gr = new Graph("input.txt");
  130. gr.ExcludeNode(2);
  131. gr.Show();
  132.  
  133. }
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement