AddEdge() public méthode

public AddEdge ( Edge x, Edge y ) : void
x Edge
y Edge
Résultat void
Exemple #1
0
        public void BuildEdge(int v1, int v2)
        {
            Vertex n1 = null, n2 = null;
            Vertex temp = Vfirst;

            while (temp != null)
            {
                int i = Decimal.Compare(v1, temp.Name);
                if (i == 0)
                {
                    //found 1st node..
                    n1 = temp;
                    break;
                }
                else
                {
                    temp = temp.Next;
                }
            }

            //check if edge already exists
            for (int i = 0; i < n1.Num_Edges; i++)
            {
                int j = Decimal.Compare(v2, n1.Adjacent[i].Name);
                if (j == 0)
                {
                    return;
                }
            }

            temp = Vfirst;
            while (temp != null)
            {
                int i = Decimal.Compare(v2, temp.Name);
                if (i == 0)
                {
                    //found 2nd node..
                    n2 = temp;
                    break;
                }
                else
                {
                    temp = temp.Next;
                }
            }

            n1.Adjacent[n1.Num_Edges++] = n2;

            Edge temp2 = new Edge(n1, n2);

            if (Efirst == null)
            {
                Efirst = temp2;
                Elast  = temp2;
            }
            else
            {
                temp2.AddEdge(Elast, temp2);
                Elast = temp2;
            }
        }
Exemple #2
0
	public void BuildEdge(int v1,int v2) {
		Vertex n1 = null,n2 = null;
		Vertex temp = Vfirst;
		
		while(temp != null) {
			int i = Decimal.Compare(v1,temp.Name);
			if(i==0) {
				//found 1st node..
				n1 = temp;
				break;
			}
			else temp = temp.Next;
		}
		
		//check if edge already exists
		for(int i=0;i<n1.Num_Edges;i++) {
			int j = Decimal.Compare(v2,n1.Adjacent[i].Name);
			if(j==0) return;
		}

		temp = Vfirst;
		while(temp != null) {
			int i = Decimal.Compare(v2,temp.Name);
			if(i==0) {
				//found 2nd node..
				n2 = temp;
				break;
			}
			else temp = temp.Next;
		}
		
		n1.Adjacent[n1.Num_Edges++]=n2;
		
		Edge temp2 = new Edge(n1,n2);
		        if(Efirst==null) {
		                Efirst = temp2;
		                Elast = temp2;
		        }
		        else {
		                temp2.AddEdge(Elast,temp2);
		                Elast = temp2;
                       }
	}