Time of Update: 2018-12-04
/*17-8-09-11-21.20.h -- 第十七章第八題 */#ifndef LAST_H_#define LAST_H_#define ADD_AN_ITEM 1#define SIZE 20/*定義資料類型*//*Name_And_Pet 暴露給使用者的資料類型*/typedef struct name_and_pet{char petname[SIZE] ;/*寵物名*/char petkind[SIZE] ;/*寵物種類*/} Name_And_Kind ;typedef
Time of Update: 2018-12-04
/*7-13-11-20-22.33.c -- 第七章第十三題*/#include <stdio.h>#include <stdlib.h>#define SIZE 8int main (void) ;void print_array (const int * const array, const int size) ;void merge_sort (int * const array, const int size) ;void merge_sort_entity (
Time of Update: 2018-12-04
話說這個東西原本以為很快就會寫好,即使是前天才看是看的.實現部分用的就是一個表和size個鏈表.可事實上我寫了不下8小時...寫完了就好啊,不然我會很鬱悶呢. 主要卡殼的地方就是定義資料類型的時候,我反反覆複更改了不下五遍.不想回憶起那些錯誤的行為,我想把我實現的思想說出來來協助自己強化記憶. 分離連結散列表用來解決衝突的問題,一旦發生衝突時就可以把資料放入相應索引指標指向的鏈表中.
Time of Update: 2018-12-04
Tree min_avl_tree(const int height){int last_node_assigned = 0 ;return gen_tree (height, &last_node_assigned) ;}Tree gen_tree (const int height, int * const lastnode){Tree tree ;if (height >= 0){tree = (Node *) malloc (sizeof (Node)) ;tree
Time of Update: 2018-12-04
Tree generate_ideal_binary_search_tree (const int height, int * const assigned_min){Tree tree ;if (height >= 0){tree = (Node *) malloc (sizeof (Node)) ;tree -> left = generate_ideal_binary_search_tree (height - 1, assigned_min) ;tree ->
Time of Update: 2018-12-04
我的第一顆AVL樹.弄了一天,雖然還沒有最終測試完畢./* AVLTree.h -- AVl樹標頭檔*//*資料類型定義*/typedef int Item ;typedef struct node{Item item ;struct node * left ;struct node * right ;int height ;} Node ;typedef Node * Position ;typedef Position Tree
Time of Update: 2018-12-04
/* AVLTree.c -- AVL樹實現檔案*/#include <stdio.h>#include <stdlib.h>#include "AVLTree.h"/*局部函式宣告*/static int Left_Above_And_Beyond_Right (const Item left, const Item right) ;static int Left_Is_Less_Than_Right (const Item left, const Item
Time of Update: 2018-12-04
/* splay_tree.h -- 伸展樹標頭檔 *//*資料類型定義*/typedef int Item ;typedef struct node{Item item ;struct node * left ;struct node * right ;} Node ;typedef Node * Position ;typedef Node * SplayTree ;/*介面函式宣告*//*操作:初始化一棵伸展樹*//*操作前:ptree
Time of Update: 2018-12-04
/*Separate_Chaining_Hash -- 分離連結散列表實現檔案*/#include <stdio.h>#include <stdlib.h>#include "Separate_Chaining_Hash.h"/*局部資料類型定義*/typedef struct pair{ListNode * parent ;ListNode * current ;} Pair ;/*局部函式宣告*/int Get_Prime_Size (const int size)
Time of Update: 2018-12-04
學樹第四天,第一課伸展樹.寫了8小時,好睏啊.感覺真好.寫完自己又讀了一遍,記下了. 貼出來,還希望有人願意跟我交流./* splay_tree.c -- 伸展樹實現檔案*/#include <stdio.h>#include <stdlib.h>#include "splay_tree.h"/*局部資料類型定義*/typedef Position Stack_Item ;typedef struct stack_node{Stack_Item item
Time of Update: 2018-12-04
/*open_addressing_hash.h -- 開放定址散列表標頭檔*/enum KindOfEntry {Legitimate, Empty, Deleted} ;/*資料類型定義*/typedef int Item ;typedef struct cell{Item item ;enum KindOfEntry info ;} Cell ;typedef struct hashtable{int size ;Cell * lists ;} * HashTable ;/*介面函式宣告*
Time of Update: 2018-12-04
/*open_addressing_hash.c -- 開放定址散列表實現檔案*/#include <stdio.h>#include <stdlib.h>#include "open_addressing_hash.h"/*局部資料類型定義*/struct apple/*我實在想不出別的名字了*/{int full ;int value ;} ;/*局部函數定義*/int Get_Prime_Value (const int size) ;int
Time of Update: 2018-12-04
/*open_addressing_double_hash.c -- 開放定址散列表雙散列實現檔案*/#include <stdio.h>#include <stdlib.h>#include "open_addressing_double_hash.h"/*局部函式宣告*/static int Get_Prime_Value (const int size) ;static int Is_A_Prime (const int number) ;static int
Time of Update: 2018-12-04
/* BinarySearchTree.c -- 二叉搜尋樹實現檔案 */#include <stdio.h>#include <stdlib.h>#include "BinarySearchTree.h"/* 局部函式宣告 */int Left_Is_Less_Than_Right (const Item left, const Item right) ;int Left_Is_More_Than_Right (const Item left, const Item
Time of Update: 2018-12-04
給定若干字串,也就是二維數組,字串指標之類的.如 ab, a, b.要求排序後為 a, ab, b.字母數為 N ,在 O(N)時間完成.這個問題,是昨天那個問題的下一個問題.我起初的方向是錯的.後來,採用了分治的方法給予實現.關於時間的分析, 每次都只對當前位置不為 NUL 的字元進行排序.所以,當然就是 O(N)了.確實,是這樣.字母的範圍,也是可以通過宏來更改的,非常方便.有實用價值. 寫部落格是個好習慣,能夠梳理我的思緒,同樣也是寫代碼時的期待.
Time of Update: 2018-12-04
/*open_addressing_hash(2).h -- 開放定址散列表標頭檔*/enum KindOfEntry {Legitimate, Empty, Deleted} ;/*資料類型定義*/typedef int Item ;typedef struct cell{Item item ;enum KindOfEntry entry ;} Cell ;typedef struct hashtable{int size ;Cell * lists ;} * HashTable
Time of Update: 2018-12-04
有關順序容器的使用,覺得可以拿出來,值得拿出來的東西,寫起來也不是那麼簡單. 剛剛去軟考報名回來,軟體設計師,又要開始了.一次小小的旅行,美麗的世界,等著我吧. 貼咯,不多說.// 9-39-2011-09-03-10.09.cpp -- 第九章第三十九題#include "stdafx.h"#include <iostream>#include <string>#include <vector>using namespace std ;const
Time of Update: 2018-12-04
這個東西,是接著上一篇的尋找矩陣乘法順序的一個實現.這個類,可以接受輸入,並且計算出最終結果. 因為最近在學習C++,所以理所當然地把這個東西寫成了類,而且是模板方式實現的.確實非常整潔.//matrix.h#ifndef MATRIX_H_#define MATRIX_H_#include <iostream>template<class T> class Matrix{private:T * * m_matrix ;int m_x, m_y ;long
Time of Update: 2018-12-04
<<AtA>>上面的一道思考題,又是一道線性時間排序的問題. 問題是這樣的,給定一個 int 型數組, 數組中每個數的位元可能不同, 如4321,有4位.數組中所有數值總位元為 N .要求在 O (N) 時間內對該數組進行排序.分析下,每次排序都取數的一位進行排序,從最低位開始,依次向左,每次只取一位.在最壞的情況下,每個數字都有M位,按照每位排序,每次排序需要的時間為 O (N / M), 總共需要 M 趟.總的時間即為 O (N / M * M), 也即 O
Time of Update: 2018-12-04
散列表的東西寫了有4天了.從對散列表不理解,到對散列表有了個大致的理解.從對實現不理解,到對實現有了大致的理解.今天上午寫了個可再散列的一套ADT,特意最佳化了代碼,因為在學習資料結構的同時也在學習代碼的最佳化,於是就應用上了.這套ADT更有通用性,包括對Item類型的比較,賦值,都通過函數來完成,而且有專門的可將Item類型拆成int類型的函數,這樣這套ADT用來作用到char *