Построение минимального остового дерева. Изучение основных алгоритмов построение минимальных остовых деревьев, страница 4

        /// <summary>

        /// Вес ребра

        /// </summary>

        public int Weight

        {

            get { return weight; }

            set { weight = value; }

        }

        public bool Contains(string vertex)

        {

            if (startV == vertex || endV == vertex)

                return true;

            else

                return false;

        }

        public int CompareTo(object obj)

        {

            Edge edg = obj as Edge;

            return startV.CompareTo(edg.startV);

            //if (startV >= edg.startV)

            //    return 1;

            //else

            //    return -1;

        }

    }

}

Класс list

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace lab4

{

    class list

    {

        string vertex;

        List<string> vList;

        public list(string vertex)

        {

            this.vertex = vertex;

            vList = new List<string>();

            vList.Add(vertex);

        }

        public string Vertex

        {

            get { return vertex; }

        }

        public List<string> VList

        {

            get { return vList; }

            set { vList = value; }

        }

        public void ClearDublicates()

        {

            vList.Sort();

            string tmp = vList[0];

            for (int i = 1; i < vList.Count; ++i)

            {

                if (vList[i] == tmp)

                {

                    vList.RemoveAt(i);

                    i--;

                }

                else

                    tmp = vList[i];

            }

        }

    }

}

Класс Program

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace lab4

{

    class Program

    {

        static void OutputList(List<Edge> edges)

        {

            string temp = edges[0].StartV;

            Console.Write(temp + "->");

            for (int i = 0; i < edges.Count; ++i)

            {

                if (temp == edges[i].StartV)

                {

                    Console.Write(edges[i].EndV + " (" + edges[i].Weight + "); ");

                }

                else

                {

                    Console.WriteLine();

                    temp = edges[i].StartV;

                    Console.Write(temp + "->");

                    Console.Write(edges[i].EndV + " (" + edges[i].Weight + "); ");

                }

            }

        }

        static void Main(string[] args)

        {

            Console.Title = "Построение минимального остовного дерева";

            List<Edge> edges;//Список ребер

            int vCount;

            Console.WriteLine("Укажите число вершин");

            vCount = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Укажите число ребер");

            int eCount = Convert.ToInt32(Console.ReadLine());

            #region Ввод

            Console.WriteLine("Вводите ребра в формате вершина вершина вес");

            edges = new List<Edge>();

            for (int i = 0; i < eCount; ++i)

            {

                try

                {

                    Console.WriteLine((i + 1) + " ребро:");

                    string tmp = Console.ReadLine();

                    Edge newEdg = new Edge(tmp.Split()[0], tmp.Split()[1], Convert.ToInt32(tmp.Split()[2]));

                    if(!edges.Contains(newEdg))

                        edges.Add(newEdg);

                    newEdg = new Edge(tmp.Split()[1], tmp.Split()[0], Convert.ToInt32(tmp.Split()[2]));