?? dic_hashopen.c
字號(hào):
/* 本程序是用開地址法解決碰撞的散列表示方法,
提供了字典的一些基本操作*/
#include<stdio.h>
#define null -1 /* null為空結(jié)點(diǎn)標(biāo)記 */
#define TRUE 1
#define FALSE 0
#define REGION_LEN 13
typedef int KeyType;
typedef int DataType;
typedef struct {
KeyType key; /* 字典元素的關(guān)鍵碼字段 */
DataType value; /* 字典元素的屬性字段 */
} DicElement;
typedef struct {
int m; /* m=REGION_LEN,為基本區(qū)域長(zhǎng)度 */
DicElement element[REGION_LEN];
} HashDictionary;
int h(KeyType key){
return key % REGION_LEN;
}
int linearSearch(HashDictionary * phash, KeyType key, int *position) {
int inc, d = h(key); /* d為散列地址,散列函數(shù)為h(key) */
for (inc = 0; inc < phash->m; inc++) {
if (phash->element[d].key == key) { /* 檢索成功 */
*position = d;
return TRUE;
}
else if (phash->element[d].key == null) {/* 檢索失敗,找到插入位置 */
*position = d;
return FALSE;
}
d = (d+1) % phash->m;
}
*position = -1; /* 散列表溢出 */
return FALSE;
}
int linearInsert(HashDictionary *phash, KeyType key) {
int position;
if(linearSearch(phash, key, &position) == TRUE )/* 散列表中已有關(guān)鍵碼為key 的結(jié)點(diǎn)*/
printf("Find\n");
else if(position != -1)
phash->element[position].key = key; /* 插入結(jié)點(diǎn),忽略對(duì)value字段的賦值 */
else return FALSE; /* 散列表溢出 */
return TRUE;
}
int main(){
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -