view defical-sharp/libsemtd/graph.cs @ 1:758381a85d76 default tip

Incorrect printf format.
author Edho Prima Arief <me@myconan.net>
date Mon, 28 Jun 2010 14:52:19 +0700
parents ebed2bd0d300
children
line wrap: on
line source

namespace libsemtd
{
    public partial class Semtd
    {
        private void draw(string graphType, int start, int end, params int[] ver_others)
        {
            if (end < start)
            {
                int temp = start;
                start = end;
                end = temp;
            }
            switch (graphType)
            {
                case "path":
                    {
                        for (int i = start; i < end; i++)
                            connectVertices(i, i + 1);
                        break;
                    }
                case "cycle":
                    {
                        draw("path", start, end);
                        connectVertices(start, end);
                        break;
                    }
                case "completebipartite":
                    {
                        for (int i = start; i <= end; i++)
                            foreach (int other in ver_others)
                                connectVertices(i, other);
                        break;
                    }
                case "wheel":
                    {
                        draw("cycle", start + 1, end);
                        draw("completebipartite", start + 1, end, start);
                        break;
                    }
                case "fan":
                    {
                        draw("path", start + 1, end);
                        draw("completebipartite", start + 1, end, start);
                        break;
                    }
                case "doublefan":
                    {
                        draw("path", start + 2, end);
                        draw("completebipartite", start + 2, end, start, start + 1);
                        break;
                    }
            }
        }
        private void connectVertices(int a, int b)
        {
            if (!this.graphConn[a, b])
            {
                this.graphConn[a, b] = this.graphConn[b, a] = true;
                this.numEdges++;
            }
        }
    }
}