Example #1
0
        public void DeleteEdge(String s1, String s2)
        {
            VertexNode u = FindVertex(s1);

            if (u == null || u.firstEdge == null)
            {
                Console.WriteLine("Start vertex / edge not present.");
                return;
            }

            if (u.firstEdge.endVertex.name.Equals(s2))
            {
                u.firstEdge = u.firstEdge.nextEdge;
                e--;
                return;
            }

            EdgeNode q = u.firstEdge;

            while (q.nextEdge != null)
            {
                if (q.nextEdge.endVertex.name.Equals(s2))
                {
                    q.nextEdge = q.nextEdge.nextEdge;
                    e--;
                    return;
                }
                q = q.nextEdge;
            }
            Console.WriteLine("Edge not found.");
        }
Example #2
0
 private void DeletefromEdgeLists(String s)
 {
     for (VertexNode p = start; p != null; p = p.nextVertex)
     {
         if (p.firstEdge == null)
         {
             continue;
         }
         if (p.firstEdge.endVertex.name.Equals(s))
         {
             p.firstEdge = p.firstEdge.nextEdge;
             e--;
         }
         else
         {
             EdgeNode q = p.firstEdge;
             while (q.nextEdge != null)
             {
                 if (q.nextEdge.endVertex.name.Equals(s))
                 {
                     q.nextEdge = q.nextEdge.nextEdge;
                 }
             }
         }
     }
 }
Example #3
0
        public bool EdgeExists(String s1, String s2)
        {
            VertexNode u       = FindVertex(s1);
            EdgeNode   curEdge = u.firstEdge;

            while (curEdge != null)
            {
                if (curEdge.endVertex.name.Equals(s2))
                {
                    return(true);
                }
                curEdge = curEdge.nextEdge;
            }
            return(false);
        }
Example #4
0
        public int OutDegree(String s)
        {
            VertexNode u = FindVertex(s);

            if (u == null)
            {
                throw new System.InvalidOperationException("Invalid vertex");
            }
            int      outd = 0;
            EdgeNode q    = u.firstEdge;

            while (q != null)
            {
                q = q.nextEdge;
                outd++;
            }
            return(outd);
        }
Example #5
0
        private void DeletefromVertexList(String s)
        {
            if (start == null)
            {
                Console.WriteLine("No vertices to be deleted.");
                return;
            }

            if (start.name.Equals(s)) // Vertex to be deleted is first vertex of list
            {
                for (EdgeNode q = start.firstEdge; q != null; q = q.nextEdge)
                {
                    e--;
                }
                start = start.nextVertex;
                n--;
            }
            else
            {
                VertexNode p = start;
                while (p.nextVertex != null)
                {
                    if (p.nextVertex.name.Equals(s))
                    {
                        break;
                    }
                    p = p.nextVertex;
                }
                if (p.nextVertex == null)
                {
                    Console.WriteLine("vertex not found.");
                    return;
                }
                else
                {
                    for (EdgeNode q = p.nextVertex.firstEdge; q != null; q = q.nextEdge)
                    {
                        e--;
                    }
                    p.nextVertex = p.nextVertex.nextVertex;
                    n--;
                }
            }
        }
Example #6
0
        public void InsertEdge(String s1, String s2)
        {
            if (s1.Equals(s2))
            {
                Console.WriteLine("Invalid edge - start and end vertices are same");
                return;
            }
            VertexNode u = FindVertex(s1);
            VertexNode v = FindVertex(s2);

            if (u == null || v == null)
            {
                Console.WriteLine("Start or End vertex not present");
                return;
            }

            EdgeNode temp = new EdgeNode(v);

            if (u.firstEdge == null)
            {
                u.firstEdge = temp;
                e++;
            }
            else
            {
                EdgeNode p = u.firstEdge;
                while (p.nextEdge != null)
                {
                    if (p.endVertex.name.Equals(s2))
                    {
                        Console.WriteLine("Edge present.");
                        return;
                    }
                    p = p.nextEdge;
                }
                if (p.endVertex.name.Equals(s2))
                {
                    Console.WriteLine("edge present.");
                    return;
                }
                p.nextEdge = temp;
                e++;
            }
        }
Example #7
0
        public int InDegree(String s)
        {
            VertexNode u = FindVertex(s);

            if (u == null)
            {
                throw new System.InvalidOperationException("Invalid vertex");
            }
            int ind = 0;

            for (VertexNode p = start; p != null; p = p.nextVertex)
            {
                for (EdgeNode q = p.firstEdge; q != null; q = q.nextEdge)
                {
                    if (q.endVertex.name.Equals(s))
                    {
                        ind++;
                    }
                }
            }
            return(ind);
        }