/* Build, find, INSERT, delete//#include <stdio.h> #define NIL-1//Assume that the keyword is a non-negative integer # define del-2typedef int KeyType; KeyType hashtable[13]; Easy to verify the algorithm, the number of keywords is assumed to be not more than 13, the hash table is set to 13//keyword insertion function void inserthashtable (KeyType k) {for (int i=0; i<13; i++) if (NIL = = HashTable [(K%13+i)%13] | | DEL = = hashtable[(k%13+i)%13]) {hashtable[(k%13+i)%13] = K;break;}} The lookup operation of the hash table, the lookup succeeds returns the following table, otherwise returns -1int Hashsearch (KeyType k) {int i = 0;while (i<13) {if (k = = hashtable[((k%13) +i)%13]) retur N ((k%13) +i)%13;else if (NIL = = hashtable[((k%13) +i)%13]) return-1;i++;} if (= = i) return-1;} Create hash table void Createhashtable () {int n; KeyType key;for (int i=0; i<13; i++) Hashtable[i] = nil;printf ("Please enter the number of keywords: \ n"), scanf ("%d", &n);p rintf ("Please enter% The value of the D keyword: \ n ", N), for (i=0; i<n; i++) {scanf ("%d ", &key), if (-1 = = Hashsearch (key)) inserthashtable (key);}} Delete operation for hash table void Deletehashtable (KeyType k) {int index = Hashsearch (k); if (-1 = = index) printf ("No this keyword!\n"); elsehashtable[i Ndex] = DEL;} Print hash table void printhashtable (void) {printf ("current hash table saveThe key word for the storage is: \ n "), for (int i=0; i<13; i++) printf ("%d ", Hashtable[i]);p rintf (" \ n ");} int main () {KeyType k; Createhashtable (); Printhashtable ();p rintf ("Please enter the keyword to insert: \ n"); scanf ("%d", &k); inserthashtable (k); Printhashtable ();p rintf ("Please enter the keyword to delete: \ n"); scanf ("%d", &k);D eletehashtable (k); Printhashtable ();p rintf ("Enter the keyword to find: \ n"), scanf ("%d", &k), and if (-1! = Hashsearch (k)) printf ("Find the keyword!\n at position%d of the current table", Hashsearch (k) +1); elseprintf ("Without this keyword!\n"); return 0;}
Full C code for find, insert, and delete operations for a closed hash list