Sequential lookup (with Lookout)

Source: Internet
Author: User
Sequential lookups can be from the front to the back, or from the back to the front. Both of these can be

(1) The most basic order lookup

int Seqsearch (seqlist l,keytype k)
{
i = l.length;
while (I >= 1 && l.r[i].key! = k)
  i--;
if (i > = 1)
   return i;
return 0;
}

(2) To optimize the order lookup, is to add a listener, the above find the way time mainly consumes the two conditions of the while loop judgment. In fact, we will find that I >= 1, this judgment can be improved. If you add a lookout, put your keywords in r[0] so you don't have to Judge i>= 1.

int Seqsearch (seqlist l,keytype k)
{
i = l.length;
L.r[i].key = k;
while (l.r[i].key! = k)
  i--;
return i;
}

There are two kinds of results returned
A. i > 0 Find success
B. i = 0 Lookup failed


The comparison of three kinds of search methods with the linear table

Order Lookup binary Find index Lookup
The structure of the table is orderly, orderly and orderly disorder
Table storage order chain sequential chain order
ASL (average lookup length) maximum minimum medium


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.