DefaultNamespace.Graph.DeleteVertex C# (CSharp) 메소드

DeleteVertex() 공개 메소드

public DeleteVertex ( ) : void
리턴 void
	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;
			}	
		}
	}
	

Usage Example

예제 #1
0
        public static void Main()
        {
            Console.WriteLine("Building Graph with 800 vertices...");
            Graph MyGraph = new Graph(800); // graph with 800 nodes

            MyGraph.BuildGraph();

            Console.WriteLine("Checking if all vertices are reachable...");
            MyGraph.CheckIfReachable();

            //Console.WriteLine("Printing the Graph...");
            //MyGraph.PrintGraph();

            Console.WriteLine("Deleting a random vertex...");
            MyGraph.DeleteVertex();

            //MyGraph.PrintGraph();

            Console.WriteLine("Done");
            Environment.ExitCode = (0);
            Console.WriteLine("Test Passed");
        }
All Usage Examples Of DefaultNamespace.Graph::DeleteVertex