DeleteAdjacentEntry() public method

public DeleteAdjacentEntry ( int n ) : void
n int
return void
Beispiel #1
0
        /*public void TraverseGraph() {
         *      Vertex root = Vfirst;
         *      int i=0,j=0;
         *      Vertex next = root.Adjacent[i];
         *
         *      while(j<Nodes) {
         *
         *                      Console.WriteLine("root: " + root.Name);
         *                      while(next != null) {
         *                              Console.WriteLine(next.Name);
         *                              if(next.Name == j) {break;}
         *                              next = next.Adjacent[0];
         *                      }
         *                      i++;
         *                      if((next = root.Adjacent[i]) == null) {
         *                              i=0;
         *                              j++;
         *                              if(root == Vlast) break;
         *                              else root = root.Next;
         *                              next = root.Adjacent[i];
         *
         *                      }
         *      }
         *
         * }*/

        public void DeleteVertex()
        {
            Vertex temp1 = null;
            Vertex temp2 = Vfirst;

            DateTime time = DateTime.Now;
            Int32    seed = (Int32)time.Ticks;
            Random   rand = new Random(seed);

            int j = rand.Next(0, Nodes);

            //Console.WriteLine("Deleting vertex: " + j);

            while (temp2 != null)
            {
                int i = Decimal.Compare(j, temp2.Name);
                if (i == 0)
                {
                    if (temp2 == Vfirst)
                    {
                        temp2  = null;
                        Vfirst = Vfirst.Next;
                        break;
                    }
                    temp1.Next = temp2.Next;
                    temp2      = null;
                    break;
                }
                else
                {
                    temp1 = temp2;
                    temp2 = temp2.Next;
                }
            }

            // Restructuring the Graph
            Console.WriteLine("Restructuring the Graph...");
            temp2 = Vfirst;
            while (temp2 != null)
            {
                temp2.DeleteAdjacentEntry(j);
                temp2 = temp2.Next;
            }

            Edge e1   = null;
            Edge e2   = Efirst;
            Edge temp = null;

            while (e2 != null)
            {
                int v1 = Decimal.Compare(j, e2.v1.Name);
                int v2 = Decimal.Compare(j, e2.v2.Name);
                if ((v1 == 0) || (v2 == 0))
                {
                    if (e2 == Efirst)
                    {
                        temp   = e2;
                        e2     = e2.Next;
                        Efirst = Efirst.Next;
                        temp   = null;
                    }
                    else
                    {
                        temp    = e1;
                        e1.Next = e2.Next;
                        e2      = e2.Next;
                    }
                }
                else
                {
                    e1 = e2;
                    e2 = e2.Next;
                }
            }
        }