templatebool prim(edgenodet)
initializepos();
int v;
t w;
vertexnode2vn2;
modifiedminheap*h;
h = new modifiedminheap(n);
first(1,v,w);
while (v)
for (int i = 0; i < n - 1; i++)
catch (outofbounds)
edgenodex;
int u = vn2.id;
x.u = u;
x.v = vn1[u].nbr;
x.weight = vn1[u].distance;
t[i] = x;
selected[u] = true;
first(u,v,w);
while (v)
else if (vn1[v].distance > w)
}
next(u,v,w);
}
}
deactivatepos();
delete vn1;
delete selected;
delete h;
return true;
} templatebool prim(edgenodet)
initializepos();
int v;
t w;
vertexnode2vn2;
modifiedminheap*h;
h = new modifiedminheap(n);
first(1,v,w);
while (v)
for (int i = 0; i < n - 1; i++)
catch (outofbounds)
edgenodex;
int u = vn2.id;
x.u = u;
x.v = vn1[u].nbr;
x.weight = vn1[u].distance;
t[i] = x;
selected[u] = true;
first(u,v,w);
while (v)
else if (vn1[v].distance > w)
}next(u,v,w);
}
}
deactivatepos();
delete vn1;
delete selected;
delete h;
return true;
}
Prim演算法實現
include stdio.h define max vertex num 20 typedef struct arccellarccell,adjmatrix max vertex num max vertex num typedef struct mgraph struct closedge m...
Prim演算法實現
prim 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 4...
實現prim演算法
如下找出該圖的最小生成樹 prim演算法是求解該類問題的一種經典演算法 prim演算法的基本思路 將圖中的所有的頂點分為兩類 樹頂點 已經被選入生成樹的頂點 和非樹頂點 還未被選入生成樹的頂點 首先選擇任意乙個頂點加入生成樹,接下來要找出一條邊新增到生成樹,這需要列舉每乙個樹頂點到每乙個非樹頂點所有...