Sequential search sequential find

Source: Internet
Author: User
# Include <stdio. h> # include <stdlib. h> typedef int keytype; struct elemtype {int key ;}; int find_seq (struct elemtype arr [], int N, keytype key) {int I = 0; (; I <n; I ++) {If (ARR [I]. key = Key) return I; printf ("check % d \ n", arr [I]);} return-1 ;}// better, there is only one judgment in the for loop. Note that data cannot cross-border int find_seq_improved (struct elemtype arr [], int N, keytype key) {int I = 0; arr [N]. key = key; // set the record for (; I ++) {If (ARR [I]. key = Key) break; printf ("check % d \ n", arr [I]);} if (I <n) return I; else return-1 ;} int main () {struct elemtype arr [10]; arr [0]. key = 0; arr [1]. key = 11; arr [2]. key = 22; arr [3]. key = 33; arr [4]. key = 44; arr [5]. key = 55; int idx = find_seq (ARR, 6,554); printf ("idx = % d \ n", idx); int idx1 = find_seq_improved (ARR, 6,554 ); printf ("idx = % d \ n", idx1); Return 0 ;}

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.