Complete C code for searching, inserting, and deleting a closed hash

Source: Internet
Author: User

Complete C code for searching, inserting, and deleting a closed hash

/* Close the creation, search, insertion, and deletion of the hash list */# include
 
  
# Define NIL-1 // assume that the keyword is a non-negative integer # define DEL-2 typedef int KeyType; KeyType HashTable [13]; // It is easy to verify the algorithm. The number of keywords is assumed to be 13, hash table length: 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 query operation for the hash table. If the query is successful, the following table is returned, otherwise, return-1int HashSearch (KeyType k) {int I = 0; while (I <13) {if (k = HashTable [(k % 13) + I) % 13]) return (k % 13) + I) % 13; else if (NIL = HashTable [(k % 13) + I) % 13]) return-1; I ++;} if (13 = I) return-1;} // create a hash table void CreateHashTable () {int n; KeyType key; for (int I = 0; I <13; I ++) HashTable [I] = NIL; printf ("Enter the number of keywords: \ n "); scanf ("% d", & n); printf ("Enter the value of % d keywords: \ n", n); for (I = 0; I
  
   

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.