C 自定義HASH表實現 衝突指標鍊錶法

2021-08-31 02:26:28 字數 1421 閱讀 7725

#include

#include

#include/* malloc()等 */

#include/* int_max等 */

#include/* eof(=^z或f6),null */

#include/* atoi() */

#include/* eof() */

#include/* floor(),ceil(),abs() */

#include/* exit() */

/* 函式結果狀態** */

#define true 1

#define false 0

#define ok 1

#define error 0

#define infeasible -1

#define eq(a,b) ((a)==(b))

#define lt(a,b) ((a)<(b))

#define lq(a,b) ((a)<=(b))

typedef int status; /* status是函式的型別,其值是函式結果狀態**,如ok等 */

typedef int boolean;

#define nullkey 0 /* 0為無記錄標誌 */

#define n 10 /* 資料元素個數 */

typedef int keytype; /* 設關鍵字域為整型 */

class elemtype

};int hashsize=; /* 雜湊表容量遞增表,乙個合適的素數序列 */

int m=0; /* 雜湊表表長,全域性變數 */

typedef struct

hashtable;

#define success 1

#define unsuccess 0

#define duplicate -1

status inithashtable(hashtable *h)

unsigned hash(keytype k)

status insertdata(hashtable *h,elemtype e)

else

(*x).next=&e;

printf("ok in\n");

++(*h).count;}}

void deletdata(hashtable *h, elemtype e)

else

--(*h).count;

printf("x is deleted");

}else

}//刪除

(*x).next=(*((*x).next)).next;

printf("ok delet\n");

--(*h).count;}}

void destroyhashtable(hashtable *h)

int main()

C 給自定義類定義Hash計算

給子定義類定義hash計算,是的可以使用標準庫的雜湊容器 unordered set 和 unordered map,有多重方法實現 1 給標準庫中的 hash equal to例項化乙個自定義類的型別 2 自定義函式物件 自定義銷售類 class sales data sales data con...

Spark 自定義hash函式

之前在spark1.6中執行的 放在了spark2上去執行,發現執行的結果不一致,定位後發現是不同版本中,hash函式的實現方式不同,導致取數結果不同。區別為 spark1.6 版本為hashcode,2.x版本為murmurhash。如果在spark2上執行spark1編寫的 需要重新定義hash...

C 自定義鍊錶

c 中的鍊錶結構在程式中十分常見,用處很廣。鍊錶結構中,每個節點由值部分和指標部分組成,值部分即儲存的資料,指標指向下乙個節點,從而使得每個節點能夠連線起來,值和指標就像骨骼和關節一樣。自定義鍊錶,首先定義出節點的結構,用類表示為 public class node定義完節點,下面開始構造list鍊...