本來在寫kruskal演算法,覺得不要讓自己太透支了,畢竟年輕的本錢很容易揮霍光掉.昨天我就沒脫衣服睡了一夜.
還要5.30起來,而且一幹就是一天呢.最近鬧心工作的事,寫了會代碼,才感覺好多了.不然腦袋裡老是這些,煩死了.
我在忍耐,一直在忍耐.就是為了,我的忍耐能夠換來周圍環境的默默"支援",也就是,沒人制止我.
也許是我的忍耐不夠,也許是我處事輕浮,總之,境況不好.無論如何,親人我要顧及,自己也要顧及.實在到萬不得已的時候,我還是會選擇為了代碼放棄一些.這才是我的未來.
好吧,曬出來,去乖乖睡覺,下班回來完成kruskal,快完成了,呵呵.
加油吧.還能怎麼樣呢.
期待生日那天....特別期待,那天給自己放假.
/*9-18(a)-12-18-02-42.c -- 第九章第十八題*/<br />#include <stdio.h><br />#include <stdlib.h><br />#include "binary_heap.h"</p><p>int main (void) ;<br />int prim (const Adjacenty_List * padj, const Hash_Table * const pht, const int start) ;</p><p>int main (void)<br />{<br />Adjacenty_List adj ;<br />Hash_Table ht ;<br />int capacity = 10 ;</p><p>Initialize_H (&ht, capacity * 2) ;<br />Initialize_A (&adj, capacity) ;<br />InitializeALine_A (&adj, &ht, 0, 'a', 0, 6, 'd', 4, 'e', 4, 'b', 3) ;<br />InitializeALine_A (&adj, &ht, 1, 'b', 0, 8, 'a', 3, 'e', 2, 'f', 3, 'c', 10) ;<br />InitializeALine_A (&adj, &ht, 2, 'c', 0, 6, 'b', 10, 'f', 6, 'g', 1) ;<br />InitializeALine_A (&adj, &ht, 3, 'd', 0, 6, 'a', 4, 'e', 5, 'h', 6) ;<br />InitializeALine_A (&adj, &ht, 4, 'e', 0, 12, 'd', 5, 'a', 4, 'b', 2, 'f', 11, 'i', 1, 'h', 2) ;<br />InitializeALine_A (&adj, &ht, 5, 'f', 0, 12, 'e', 11, 'b', 3, 'c', 6, 'g', 2, 'j', 11, 'i', 3) ;<br />InitializeALine_A (&adj, &ht, 6, 'g', 0, 6, 'f', 2, 'c', 1, 'j', 8) ;<br />InitializeALine_A (&adj, &ht, 7, 'h', 0, 6, 'd', 6, 'e', 2, 'i', 4) ;<br />InitializeALine_A (&adj, &ht, 8, 'i', 0, 8, 'h', 4, 'e', 1, 'f', 3, 'j', 7) ;<br />InitializeALine_A (&adj, &ht, 9, 'j', 0, 6, 'i', 7, 'f', 11, 'g', 8) ;<br />prim (&adj, &ht, 0) ;<br />PrintAdjacenty_List_A (&adj, &ht) ;</p><p>Release_H (&ht) ;<br />Release_A (&adj) ;</p><p>return 0 ;<br />}</p><p>int prim (const Adjacenty_List * padj, const Hash_Table * const pht, const int start)<br />{<br />Binary_Heap bh ;<br />Vertex * v ;<br />Adjoin_To_Vertex * w ;<br />int capacity = (*padj) -> capacity, i ;</p><p>Initialize_B (&bh, capacity * 2) ;<br />(*padj) -> list[start].dist = 0 ;<br />for (i = 0; i < capacity; i++)<br />Insert_B (&bh, (*padj) -> list + i) ;<br />while (1)<br />{<br />do<br />{<br />v = DeleteMin_B (&bh) ;<br />if (NEGATIVEINFINITY == v -> dist)<br />break ;<br />}<br />while (TRUE == (*pht) -> lists[v -> hash_value].be_deleted)<br />;<br />if (NEGATIVEINFINITY == v -> dist)<br />break ;<br />(*pht) -> lists[v -> hash_value].be_deleted = TRUE ;<br />v -> known = TRUE ;<br />w = v -> adjoin_to ;<br />while (w)<br />{<br />if (FALSE == (*padj) -> list[(*pht) -> lists[w -> hash_value].index_in_adjacenty_list].known)<br />{<br />if (w -> cvw < (*padj) -> list[(*pht) -> lists[w ->hash_value].index_in_adjacenty_list].dist)<br />{<br />(*padj) -> list[(*pht) -> lists[w -> hash_value].index_in_adjacenty_list].dist = w -> cvw ;<br />(*padj) -> list[(*pht) -> lists[w -> hash_value].index_in_adjacenty_list].path = (*pht) -> lists[v -> hash_value].name ;<br />}<br />Insert_B (&bh, (*padj) -> list + (*pht) -> lists[w -> hash_value].index_in_adjacenty_list) ;<br />}<br />w = w -> next ;<br />}<br />}<br />Release_B (&bh) ;</p><p>return 1 ;<br />}