Exemplo n.º 1
0
        // compute the degree of v (with hove many vertexes current vertex is connected
        public static int Degree(Graph G, int v)
        {
            int degree = 0;
            foreach (var vertex in G.Adj(v))
            {
                degree += 1;
            }

            return degree;
        }
Exemplo n.º 2
0
        // count self-loops
        public static int numberOfSelfLoops(Graph G)
        {
            int count = 0;
            for (int v = 0; v < G.V; v++)
            {
                foreach (int w in G.Adj(v))
                {
                    if (v == w)
                    {
                        count++;
                    }
                }
            }

            return count / 2; // each edge counted twice
        }