Time of Update: 2018-12-04
一晃又好幾天沒有更新部落格,很是鬱悶啊.這個左式堆,不想繼續寫下去了,寫得很吃力,於是先告一段落吧.畢竟學習資料結構不是一朝一夕的事情.今後會回頭來看的.貼代碼./*lefttist_heap.h -- 左式堆標頭檔*/#define INSERT(h, x) h = Insert (h, x)/*宏和參數之間不能有空格*/#define DELETEMIN(h) (h = DeleteMin (h))/*資料類型定義*/typedef int Item ;typedef struct
Time of Update: 2018-12-04
/*lefttist_heap.c -- 左式堆實現檔案*/#include <stdio.h>#include <stdlib.h>#include "lefttist_heap.h"/*局部ADT定義*/typedef Node Item2 ;typedef struct node2{Item2 item2 ;struct node2 * next ;} Node2 ;typedef struct queue{Node2 * front ;Node2 * rear ;
Time of Update: 2018-12-04
雖然今天距昨天只有一天, 我還是成長了好多.對於昨天不懂的問題,今天搞清楚了大半.總體來說,總結起來,...都寫到代碼裡了.還要去看數學,就不多寫了.呵呵.總之,明天會更好./*skew-heap.h -- 斜堆標頭檔*/#define INSERT(heap, item) (heap = Insert (heap, item))#define DELETEMIN(heap, pnode) (heap = DeleteMin (heap, pnode))#define BUILD(heap,
Time of Update: 2018-12-04
這個斜堆沒有XX檢測.也正因為我不明白書上說的是什麼意思,才沒有寫出來.不過,那似乎是個理論上100%可以避免的檢測.或者,至少來說,一些事實驗證了代碼的正確性. 希望高手指正!/*skew-heap.c -- 斜堆實現檔案*/#include <stdio.h>#include <stdlib.h>#include "skew-heap.h"/*局部ADT聲明*//*Item1定義為指標類型在釋放原空間後會造成非法的儲存空間引用*//*得到的經驗教訓是:
Time of Update: 2018-12-04
/*binomial-queue.h -- 二項隊列標頭檔*//*標頭檔載入放在標頭檔是個好主意*/#include <stdio.h>#include <stdlib.h>#define INFINITY 32767/*資料類型定義*/typedef int Item ;//為什麼我如此喜歡 int ^ ^typedef struct node{Item item ;struct node * left ;//左子樹struct node * nextsibling ;
Time of Update: 2018-12-04
<<AtA>>上的一道思考題.昨天開始琢磨,今天又琢磨到現在.我承認我腦袋比較迷糊,但也有點慢得讓我接受不了了."不急跬步,無以至千裡;不積小流,無以成江海",只能如此安慰自己了.呵呵. 問題本身就是,給定 N 個數的集合S, S {X | X ∈ S, 0 <= X <= k).恩.書上是1,我這裡出現的是0.多了個數罷了.要求是,修改計數排序,以完成在 O (N + K) 時間完成排序的任務,並且只能使用 O (K) 的儲存空間.
Time of Update: 2018-12-04
/*open_addressing_hash_with_hashing_again.c -- 開放定址散列表線性探測法可再散列實現檔案*/#include <stdio.h>#include <stdlib.h>#include "open_addressing_hash_with_hashing_again.h"/*局部函式宣告*/static int Get_Prime_Value (const int size) ;static int Is_A_Prime
Time of Update: 2018-12-04
/*binomial-queue.c -- 二項隊列實現檔案*/#include "binomial-queue.h"/*局部函式宣告*/static SubTree Combine_Trees (SubTree t1, SubTree t2) ;static Node * Make_Node (const Item item) ;static void Recursively (const SubTree t, void (* pfun) (const Item item))
Time of Update: 2018-12-04
兩天時間,白天看虛擬儲存空間,晚上到家寫這個東西,剛剛寫完.缺點不少,功能實現是必須的. 這個東西,是根據習題的要求寫的,關於盒子問題,所以我給它取了個名字--盒子樹.呵呵. 在寫代碼的過程中,我希望寫完之後大肆慶祝下,.可寫完之後,又覺得沒什麼...呵呵 對於這個東西,我解釋下我的分析. 總體要求,就是要求有序.於是我選擇了二叉搜尋樹,考慮過AVL樹,後來覺得新東西,還是先簡單地實現下.
Time of Update: 2018-12-04
/*box.c -- 盒子問題實現檔案*/#ifndef GENERIC#include "box.h"#endif/*局部函式宣告*/static Box * Make_Box (const Weight capacity) ;static Box * Find_Max (Box * box) ;static Box * Find_Min (Box * box) ;static int Insert_ (BoxTree * const pbt, const Weight capacity,
Time of Update: 2018-12-04
終於開始接觸排序了.實現可以理解,複雜度的分析對我來說很難./*7-1-11-19-00.01.c -- 第七章第一題*/#include <stdio.h>#include <stdlib.h>#define SIZE 9typedef int Item ;int main (void) ;void insert_sort (Item * array, const int size) ;void print_array (const Item * const
Time of Update: 2018-12-04
/*7-4-11-19-19.58.c -- 第七章第四題*/#include <stdio.h>#include <stdlib.h>#define SIZE 9int main (void) ;void print_array (const int * array, const int size) ;void shell_sort (int * array, const int size) ;int main (void){int array[SIZE] = {9,
Time of Update: 2018-12-04
計數排序,白天手機看維基百科看到的.對付資料跨度小的 int 型資料,的確很快.代碼,很直觀./*count_sort-11-03-21-19.01.c -- 計數排序*/#include <stdio.h>#include <stdlib.h>#define SIZE (10)int main (void) ;int countSort (int * const array, const int size) ;void printResult (const int *
Time of Update: 2018-12-04
/*7-11-11-19-22.12.c -- 第七章第十一題*/#include <stdio.h>#include <stdlib.h>#define LEFTCHILD(position) ((position) * 2 + 1)/*Notice the space*/#define SIZE 12int main (void) ;void print_array (const int * const array, const int size) ;void
Time of Update: 2018-12-04
話說這個東西寫到淩晨3點27分,都沒有寫好.剛才睡醒了寫完的.主要遇到的問題就是當數組大小不是2的冪的時候發生的 right_end 越界的時候.我的邏輯起初偏於複雜,後來重新組織邏輯,當發生 right_end 越界的時候, 取 size - 1 為 right_end, 並且保持前一個數組完整, 後一個數組的大小不去顧及. 這樣問題就解決了. 這貌似加深了我對歸併排序的理解./*7-14-11-21-00.21.c -- 第七章第十四題*/#include
Time of Update: 2018-12-04
看<<AtA>>,講計數排序後面的一道習題.確實,睾丸之後,耳朵裡面略疼,呵呵. 指定的資料,在 min ~ max 範圍內,確定其中資料在 start ~ end 的資料的個數.因為是計數排序的習題,很自然地想到藉助於計數排序解決,或者,是一部分,或者,是變體.其實,這一部,貌似很難.只不過,在那個時刻,理所當然地想到了. 之後,很快就寫好了.寫好了的時候, min 只能為 0 .
Time of Update: 2018-12-04
實現檔案.裡面的細節,關係到輸出的方式.可以選擇多種輸出方式,沒有大肆封裝.//block.cpp -- 類比整合電路板實現檔案#include "stdafx.h"#include "block.h"namespace block{//private:void Test :: m_Merge (const int left, const int leftEnd, const int right, const int rightEnd){int i, j, k ;for (i = left,
Time of Update: 2018-12-04
就感覺,自己對這些個排序.至少,腦袋裡還沒有.哎,我老是不專心呢.加油吧. 說說快速排序吧.這東西,原理就是不斷地將一個數組分成3部分.保持所有數組處在這種狀態,最終完成排序. 這些思想,還沒有掌握.加油吧,我還能說什麼? 說些這個,呵呵. 這段代碼,起初不懂.後來,隨著不斷手工類比,發現,採用了很多技巧.也難怪起初根本理解不了.自己試著手工按照代碼上的去做,再按照自己的想法做了下,就清晰多了.確實很多技巧.
Time of Update: 2018-12-04
這個東西,對於數學上的分析我看明白了90%.但並未做深入研究.這個代碼是抄來的,核心部分是抄來的.感覺不錯. 產生固定的隨機數序列,只要種子一樣的話.這個隨機數產生器比較透明,而且較容易改動.很不錯. 每次實現代碼的時候,都會發現很多問題.而且,一旦寫上了代碼,時光就飛逝了...很不錯. 好吧,帖出來吧.又是來網吧,又是邊下電影邊寫Blog,呵呵.很不錯./*10-35-11-02-08-20.11.c -- 第十章第三十五題*/#include
Time of Update: 2018-12-04
回溯演算法.話說這東西也是經曆過各種磨難才寫出來的.寫出來之後,就不想再多說些什麼了./*10-40-11-02-16-06.10.c -- 第十章第四十題*//*02-18-01.54 完成.大概用了13小時.*/#include <stdio.h>#include <stdlib.h>#define FALSE (0)#define TRUE (1)typedef int Item ;typedef int BOOL ;/*Data is a kind of