我在開發函數來計算圖形每個頂點的三角形數量方面遇到一些困難。此圖是一個鄰接列表。我做了 Is_Edge函數返回1,如果V1和V2之間有邊緣,這可能會有所幫助。任何提示?這些結構如下:C中頂點的三角形數量
struct AdjListNode
{
int dest;
int TrianglesNumber;
int weight;
struct AdjListNode* next;
};
struct AdjList
{
struct AdjListNode *head;
};
struct Graph
{
int V;
struct AdjList* array;
};
int Is_Edge(struct Graph *Graph,int V1,int V2){
int find=0;
if(V1 > Graph->V || V2 > Graph->V)
return 0;
else{
struct AdjListNode *aux = Graph->array[V1].head;
while((aux!=NULL)&&(!find)){
if(aux->dest == V2)
find = 1;
else
aux = aux->prox;
}
return(find);
}
}
我認爲你正在將「三角形」定義爲沒有任何自我邊緣的三邊循環。你可以用各種方式解決問題;一個是基於鄰接列表的有界深度優先搜索。也就是說,探索從所討論的頂點開始的三條邊路徑,並計算該頂點有多少尾端。你的數據結構表明了一個有向圖;如果它不是無向的,那麼你可能需要除以二來解釋你可以遍歷每個三角形的兩個不同的方向。 –