Java Implementation Order Lookup

Source: Internet
Author: User

1  packagesearch;2 3 Importjava.util.Scanner;4 5 /*typically, The average number of times a keyword is compared during a lookup, also called the average lookup length (ASL), is the criterion for measuring the efficiency of a search algorithm:6 * asl= summation (p[i]*c[i]), (i=1~n). p[i] the probability of finding the first record, c[i] the number of times that I have found the first record to compare*/7 /*the idea of sequential lookups: starting at one end of the table, sequentially scanning the linear table, sequentially comparing the scanned keyword to the given value k, if the currently scanned keyword is equal to k, the lookup succeeds,8 * If no record of the keyword equals k is found after the scan is complete, the lookup fails. 9 * ASL1 Find success (sum) I/n,i=1~n.Ten * ASL2 find failed n*/ one  a //the first line enters the sequence to find, the second line enters the keyword -  public classShunxusearch { -  the      public Static voidmain (string[] Args) { -Scanner cin =NewScanner (system.in); -string[] s=NewString[2]; -          for(intI =0;i<2;i++){ +s[i] =Cin.nextline (); -         }             +string[] st = S[0].split (""); a         int[] C =New int[st.length]; at          for(intj=0;j<st.length;j++){ -c[j]=Integer.parseint (st[j]); -         } -         intKey = Integer.parseint (s[1]); -         intresult =Search (c,key); - System.out.println (result); in Cin.close ();  -     } to      public Static intSearchint[] R,intk) { +         inti,n=r.length; -          for(i=0;i<n;i++){ the             if(r[i]==k) { *                 returni; $             }    Panax Notoginseng         } -         return-1; the     } +}

Java Implementation Order Lookup

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.