工作要用到的。慢慢再重头写写吧。好几个月不写代码了。慢慢深入。加油
HashTable,以mod 10为函数存储。
#include <stdio.h> #include <stdlib.h> #include <string.h>#define NULL 0typedef struct _NODE {int value;struct _NODE *next; }NODE;//Elements mod 10 to save in hashtable; typedef struct _HASH_TABLE {NODE *arr[10]; }HASH_TABLE;HASH_TABLE *CreateHashTable() {HASH_TABLE *pHashTable=(struct _HASH_TABLE*)malloc(sizeof(HASH_TABLE));memset(pHashTable,0,sizeof(HASH_TABLE));return pHashTable; }NODE* HashFind(HASH_TABLE* pHashTable,int data) {NODE *pNode;if(pHashTable==NULL){return NULL;}if(NULL==(pNode=pHashTable->arr[data%10])){return NULL;}while(pNode){if(pNode->value==data){return pNode;}pNode=pNode->next;}}void HashInsert(HASH_TABLE *pHashTable, int data) {NODE *pNode,*pTem;pNode=(struct NODE*)malloc(sizeof(NODE));pNode=pHashTable->arr[data%10];if(pNode==NULL){pNode->value=data;pNode->next=NULL;pHashTable->arr[data%10]=pNode;}else{while(pNode->next!=NULL){pNode=pNode->next;}pTem=(struct NODE*)malloc(sizeof(NODE));pTem->value=data;pTem->next=NULL;pNode->next=pTem;} }int main() {return 0; }
java hashtable?