Java data structures and algorithms------Hash Lookup

Source: Internet
Author: User

1  PackageIYou.neugle.search;2 3  Public classHash_search {4     Private Static intm = 13;5     Private Static int[] hash =New int[m];6     Private Static int[] Array =New int[] {13, 25, 2, 60, 39, 52 };7 8      Public Static voidMain (string[] args) {9 Inserthash ();TenSYSTEM.OUT.PRINTLN ("Hash table is established as follows:"); OneSystem.out.print ("["); A          for(inti = 0; i < hash.length; i++) { - System.out.print (Hash[i]); -             if(I! = hash.length-1) { theSystem.out.print (","); -             } -         } -System.out.println ("]"); +System.out.println ("39 in hash Table position:" + searchhash (39)); -     } +  A      Public Static voidInserthash () { at         //The method of dividing and taking remainder -          for(inti = 0; i < Array.Length; i++) { -             intValue =Array[i]; -             intAddress = value%m; -              while(hash[address]! = 0) { -Address = (++address)%m; in             } -Hash[address] =value; to         } +     } -  the      Public Static intSearchhash (intkey) { *         //Open Address Law $         intAddress = key%m;Panax Notoginseng          while(hash[address]! = 0 && hash[address]! =key) { -Address = (++address)%m; the         } +  A         if(hash[address] = = 0) { the             return-1; +         } -         returnaddress; $     } $}

Java data structures and algorithms------Hash Lookup

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.