12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- namespace ConsoleApp4
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int lastTop = 0;
- int lastSheet = 0;
- List<int> codPrufer = new List<int>();
- using (StreamReader sr = new StreamReader("CodPrufera.txt"))
- {
- while (sr.EndOfStream != true)
- {
- string[] array = sr.ReadLine().Split(" ");
- for(int i = 0; i < array.Length; i++)
- {
- codPrufer.Add(Convert.ToInt32(array[i]));
- }
- }
- }
- Console.WriteLine("Код Прюфера: ");
- foreach (int i in codPrufer)
- {
- Console.Write(i+" ");
- }
- List<int> tree1 = new List<int>();
- List<int> tree2 = new List<int>();
- List<int> sheet = new List<int>();
- int a = codPrufer.Count + 1;
- for(int i = 0;i< codPrufer.Count + 2; i++)
- {
- sheet.Add(i+1);
- }
- Console.WriteLine("\nДополнительный массив: ");
- foreach (int i in sheet)
- {
- Console.Write(i + " ");
- }
- lastTop = codPrufer.Last();
- while (codPrufer.Count <= a && codPrufer.Count>0)
- {
- int minimum = 10;
- int minimumIndex = 0;
- for (int i = 0; i < sheet.Count; i++)
- {
- if (codPrufer.Contains(sheet[i]) != true)
- {
- if (minimum > sheet[i])
- {
- minimum = sheet[i];
- minimumIndex = i;
- }
- }
- }
- tree1.Add(codPrufer[0]);
- tree2.Add(minimum);
- codPrufer.RemoveAt(0);
- sheet.RemoveAt(minimumIndex);
- lastSheet = sheet.Last();
- Console.WriteLine();
- }
-
- tree1.Add(lastTop);
- tree2.Add(lastSheet);
- Console.WriteLine("\nРебра графа");
- for(int i = 0;i < tree2.Count;i++)
- {
- Console.WriteLine(tree1[i]+" - " + tree2[i]);
- }
- using (StreamWriter sw = new StreamWriter("tree.txt", false))
- {
- for (int i = 0; i < tree2.Count; i++)
- {
- sw.WriteLine(tree1[i] + " - " + tree2[i]);
- }
- }
- }
- }
- }
|