I do not know people at the beginning to see the "Data Structure and algorithm analysis--c language description" when the hash of a chapter, can not understand the contents of the book, Little ZZ Look at the time did not see how to understand. So went to ask degrees Niang, degrees Niang gave me such an article. It introduces the basic definition of hashing and the commonly used method of implementation, which is quite easy to understand (perhaps the IQ is a bit clumsy).
http://blog.csdn.net/u010275850/article/details/44963701
First read this blog post, and then read the conclusion, suddenly suddenly realized that there are wood ah.
Refer to the book on the program ideas, the following general operation of the hash list is programmed as follows:
/* Split Link Method Construction hash */#include <stdio.h> #include <stdlib.h> #define tbsize 10typedef struct listnode{int data; struct ListNode *next;} list,*list;typedef struct hashnode{int tablesize; List *thelists;} HASH,*HT; HT initht (int tablesize);//Initialization Routines list find (int data,ht H);//find operation int hash (int data,int tablesize);//hash function void Insert (int Data,ht h);//insert operation void Delete (int data,ht h);//delete operation void printht (HT H);//print entire hash table void Printlist (list L);//Print List int main () { int data[10]={0,1,4,9,16,25,36,49,64,81}; int i=0; HT h; H=INITHT (10); if (h==null) printf ("Out of space!\n"); for (i=0;i<10;i++) {insert (DATA[I],H); } printht (h); Insert (7,H); Insert (59,H); printf ("After insert 7 and 59:\n"); PRINTHT (h); Delete (36,H); printf ("After delete 36:\n"); PRINTHT (h); Find (7,H); Find (49,H); Find (36,H); return 0;} HT initht (int tablesize) {HT H; int i; H=malloc (sizeof (struct hashnode)); if (h==null) printf ("Out of SPACE!\n "); h->tablesize=tbsize; H->thelists=malloc (sizeof (list) *h->tablesize); if (h->thelists==null) printf ("Out of space!\n"); for (i=0;i
Data structure Learning--hash list ADT (programmatic)