標頭檔案中的原始定義
主函式#ifndef _helpsep_h
#define mintablesize 1
typedef
char
*elementtype;
struct listnode;
typedef
struct listnode *position;
struct hashtbl;
typedef
struct hashtbl *hashtable;
hashtable initializetable
(int tablesize)
;position find
(elementtype key, hashtable h)
;void
insert
(elementtype key, hashtable h)
;#endif
// !_helpsep_h
#pragma once
執行結果:#include
#include
#include
#include
"malloc.h"
#include
"hashhelp.h"
#define _crt_secure_no_deprecate
#define _crt_secure_no_warnings
// 定義雜湊函式的返回值
typedef
unsigned
int index;
struct listnode
;typedef position list;
struct hashtbl
;// 雜湊函式
index hash
(const
char
*key,
int tablesize)
;int
nextprime
(int tablesize)
;int
main()
// 乙個好的雜湊函式:1)在雜湊表中均勻分配; 2)計算速度快
index hash
(const
char
*key,
int tablesize)
return hashval % tablesize;
}// 這個函式待完善:產生乙個素數
intnextprime
(int tablesize)
hashtable initializetable
(int tablesize)
h =(hashtable)
malloc
(sizeof
(struct hashtbl));
if(h ==
null
) h->tablesize =
nextprime
(tablesize)
; h->thelists =
(list *
)malloc
(sizeof
(list)
* h->tablesize);if
(h->thelists ==
null
)for
(i =
0; i < h->tablesize; i++
)else
}printf
("\n初始化表成功!\n");
return h;
}position find
(elementtype key, hashtable h)
return p;
}void
insert
(elementtype key, hashtable h)
else
}}
簡單echo server的C語言實現
下決心要重新梳理一下網路的相關知識,計畫要熟悉tcpdump工具以及linux網路程式設計,尤其是要把同步非同步,阻塞非阻塞那塊弄清楚,如果可能的話,熟悉一下libuv這樣的庫。本週參照網上資料的 實現了乙個簡單echo server,從socket中讀取資料並且寫回,用telnet測試後發現成功,...
C語言實現簡單的飛機大戰
定義四個函式實現飛機大戰 include include include 定義全域性變數 int high,width 定義邊界 int position x,position y 飛機位置 int bullet x,bullet y 子彈位置 int enemy x,enemy y int sco...
C語言實現簡單的檔案讀寫
這是乙個用c語言進行檔案讀取檔案的乙個控制台程式。讀取的檔案為乙個txt檔案,裡面存放乙個5 5的矩陣,對檔案的處理為矩陣乘2。首先要想更好的理解這個 必須了解計算機處理檔案的具體過程 檔案讀取的資料流。本文參考譚浩強老師的至尊寶典 c語言程式設計 1.定義檔案指標 file in,out 定義檔案...