Develop non-recursive functions to perform search for a Key value in a given list using (i) Linear Search

 \* linear search non recursive*\

#include<stdio.h>

int lsearch(int a[],int key,int low,int high);

int main()

{

int a[10],n,key,found;

clrscr();

printf("\n enter no of elements");

scanf("%d",&n);

printf("\n enter %d elements",n);

for(i=0;i<n;i++)

{

scanf("%d",&a[i]);

}

printf("\n enter key to search:");

scanf("%d",&key);

found=lsearch(a,key,0,n-1)

if(found==-1)

printf("\n unsuccessful search key not found");

else

printf("\n successful search key %d is available at index %d",key,found);

return 0;

}

int lsearch(int a[],int key,int low,int high)

{

while(low<=high)

{

if(key==a[low])

return low;

else

low=low+1;

}

return-1;

}

Comments

Popular posts from this blog

Create a Binary Search Tree of integers and perform the following operations (i)insert (ii) delete (iii). Search (iv) traversals (pre-order, in-order, post-order) BST

Creation Of DLL

Develop non-recursive functions to perform search for a Key value in a given list using (i) Binary Search Non Recursive