Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

Kruskal Algorithm

, 5 Jul 2012 CPOL
Implementation of Kruskal Algorithm in C#
KruskalAlgorithm.zip
KruskalAlgorithm
Client
bin
Debug
Client.exe
Client.pdb
Client.vshost.exe
Client.vshost.exe.manifest
Kruskal.dll
Kruskal.pdb
KruskalAlgorithm.exe
KruskalAlgorithm.vshost.exe.manifest
Release
obj
x86
Debug
Client.exe
Client.pdb
Client.Properties.Resources.resources
DesignTimeResolveAssemblyReferencesInput.cache
GenerateResource.read.1.tlog
GenerateResource.write.1.tlog
Kruskal.frmCost.resources
Kruskal.frmMain.resources
TempPE
Properties.Resources.Designer.cs.dll
Properties
Settings.settings
Kruskal
bin
Debug
Kruskal.dll
Kruskal.pdb
Release
Contracts
Entities
Implementation
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
Kruskal.dll
Kruskal.pdb
TempPE
Properties
KruskalAlgorithm.sln.docstates.suo
KruskalAlgorithm.suo
KruskalAlgorithm.vsmdi
Local.testsettings
TestResults
Omar_OMAR-PC 2012-07-02 14_38_22.trx
Omar_OMAR-PC 2012-07-02 18_16_57.trx
Omar_OMAR-PC 2012-07-02 18_20_20.trx
Omar_OMAR-PC 2012-07-02 18_20_27.trx
Omar_OMAR-PC 2012-07-02 18_23_20.trx
Omar_OMAR-PC 2012-07-02 18_23_20
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-02 18_24_35.trx
Omar_OMAR-PC 2012-07-02 18_24_35
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-02 18_27_14.trx
Omar_OMAR-PC 2012-07-02 18_27_14
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-02 18_29_28.trx
Omar_OMAR-PC 2012-07-02 18_29_28
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-03 15_36_58.trx
Omar_OMAR-PC 2012-07-03 15_38_50.trx
Omar_OMAR-PC 2012-07-03 15_38_50
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-03 15_43_17.trx
Omar_OMAR-PC 2012-07-03 15_43_17
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-03 15_45_42.trx
Omar_OMAR-PC 2012-07-03 15_46_25.trx
Omar_OMAR-PC 2012-07-03 15_46_25
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-03 16_06_02.trx
Omar_OMAR-PC 2012-07-03 16_06_05.trx
Omar_OMAR-PC 2012-07-03 16_06_05
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-03 16_08_00.trx
Omar_OMAR-PC 2012-07-03 16_08_00
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-03 16_08_16.trx
Omar_OMAR-PC 2012-07-03 16_08_16
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-03 16_10_25.trx
Omar_OMAR-PC 2012-07-03 16_10_25
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-03 16_11_27.trx
Omar_OMAR-PC 2012-07-03 16_11_27
In
OMAR-PC
Out
AgentRestart.dat
Omar_OMAR-PC 2012-07-03 16_13_46.trx
Omar_OMAR-PC 2012-07-03 16_16_19.trx
Omar_OMAR-PC 2012-07-03 16_16_46.trx
Omar_OMAR-PC 2012-07-05 20_04_47.trx
Omar_OMAR-PC 2012-07-05 20_08_10.trx
Omar_OMAR-PC 2012-07-05 20_08_33.trx
TraceAndTestImpact.testsettings
UnitTests
AlgorithmTest
bin
Debug
Kruskal.dll
Kruskal.pdb
Kruskal_Accessor.dll
Kruskal_Accessor.pdb
UnitTests.dll
UnitTests.pdb
Release
EntitiesTest
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
Kruskal_Accessor.dll
Kruskal_Accessor.pdb
ResolveAssemblyReference.cache
TempPE
UnitTests.dll
UnitTests.pdb
Properties
Test References
Kruskal.accessor
KruskalDemo.zip
KruskalDemo
KruskalAlgorithm.exe
KruskalAlgorithm.pdb
KruskalAlgorithm.vshost.exe
KruskalAlgorithm.vshost.exe.manifest
kruskalsrc.zip
KruskalAlgorithm.suo
KruskalAlgorithm
bin
Debug
KruskalAlgorithm.exe
KruskalAlgorithm.vshost.exe
KruskalAlgorithm.vshost.exe.manifest
Release
Properties
Settings.settings
using System;
using System.Drawing;

namespace Kruskal
{
    public class Vertex
    {
        #region Members

        private int name;

        #endregion

        #region Public Properties

        public int Name
        {
            get
            {
                return name;
            }
        }

        public int Rank { get; set; }

        public Vertex Root { get; set; }

        public Point Position { get; set; }

        #endregion

        #region Constructor

        public Vertex(int name, Point position)
        {
            this.name = name;
            this.Rank = 0;
            this.Root = this;
            this.Position = position;
        } 

        #endregion

        #region Methods

        internal Vertex GetRoot()
        {
            if (this.Root != this)// am I my own parent ? (am i the root ?)
            {
                this.Root = this.Root.GetRoot();// No? then get my parent
            }

            return this.Root;
        }

        internal static void Join(Vertex root1, Vertex root2)
        {
            if (root2.Rank < root1.Rank)//is the rank of Root2 less than that of Root1 ?
            {
                root2.Root = root1;//yes! then Root1 is the parent of Root2 (since it has the higher rank)
            }
            else //rank of Root2 is greater than or equal to that of Root1
            {
                root1.Root = root2;//make Root2 the parent
                if (root1.Rank == root2.Rank)//both ranks are equal ?
                {
                    root2.Rank++;//increment Root2, we need to reach a single root for the whole tree
                }
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Omar Gameel Salem
Software Developer
Australia Australia
Enthusiastic programmer/researcher, passionate to learn new technologies, interested in problem solving, data structures, algorithms and automation.
 
Amateur guitarist/ keyboardist, squash player.
 
If you have a question\suggestion about one of my articles, or you want an algorithm implemented in C#, feel free to contact me.
Follow on   LinkedIn

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 5 Jul 2012
Article Copyright 2011 by Omar Gameel Salem
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid