Open Means Open Means

 

SEQUENTIAL SEARCH / LINEAR SEARCH

 

Definition Of Linear Search:


A key is a value that you are looking for in an array.The simplest type of searching process is the sequential search.

Note: In the sequential search, each element of the array is compared to the key, in the order it appears in the array, until the first element matching the key is found.


Example:

#include

int main(void)

{
      int a[10];

a[0]=20;

a[1]=40;

a[2]=100;

a[3]=80;

a[4]=10;

a[5]=60;

a[6]=50;

a[7]=90;

a[8]=30;

a[9]=70;

cout<< "Enter the number you want to find     (from 10 to 100)…";

int key;
cin>> key; 

int flag = 0;    // set flag to off

for(int i=0; i<10; i++)    // start to loop through
the array

{

if (array[i] == key)   // if match is found

{

flag = 1;   // turn flag on

break ;    // break out of for loop

}

}

if (flag)    // if flag is TRUE (1)

{
 
cout<< "Your number is at subscript position"<}

else

{

cout<< "Sorry, I could not find your number in this array."<}      

return 0;

}

 

 

 

Thankyou,

Rajkumar

No comments

Login to post a comment

Show
  • Create an account
  • Forgot your username?
  • Forgot your password?

Related Articles

  • Oracle IMP & EXP Command Line Tools
  • The good way of creating the Struts Application
  • Java Coding Best Practices - Coding Guidelines
  • My Interview Experience with ADP
  • Canara Bank Specialist Officers - Computer Programmer Written Exam Paper
  • Oracle's DDBMS Funtionality
  • Data Compression
  • Online Money Making Through PTC
  • The New Microsoft search Engine---BING
  • Death of Originality.
  • About Us
  • Faqs
  • Contact Us
  • Disclaimer
  • Terms & Conditions