Answer Posted / saisharath
#include<stdio.h>
#include<conio.h>
int nr_bin_search(int[],int,int);
void main()
{
int key,i,n,index,l[20];
printf("\n enter the number of elements in the list:");
scanf("%d",n);
printf("\n enter the elements of the list:");
for(i=0;i<n;i++)
scanf("%d",&l[i]);
printf("\n enter the key element to be searched in the
list:");
scanf("%d",&key);
index=nr_bin_search(l,n,key);
if(index==-1)
printf("\n search completed,element%d found in the list at
position %d",key,index);
getch();
}
int nr_bin_search(ints[],int n,int e)
{
int low_val,mid_val,high_val;
low_val=0;
high_val=0;
while(high_val>=low_val)
{
mid_val=(low_val+high_val)/2;
if(s[mid_val]==e)
return(mid_val);
if(s[mid_val]<e)
low_val=mid_val+1;
else
high_val=mid_val-1;
}
return-1;
}
| Is This Answer Correct ? | 11 Yes | 13 No |
Post New Answer View All Answers
Explain how is linked list implemented?
Which sorting is used in collections sort?
Explain the sorting algorithm that is most suitable to be used with single linked list?
Compare Queue and Topic ?
Can map contain duplicate keys?
Is array a linked list?
What are the major data structures used in the following areas : network data model & hierarchical data model?
How does a selection sort work?
What is difference between map and hashmap?
Why do we need a data structure?
What are the advantages of selecetion sort?
How do I sort hashset?
What is sequential mapping in data structure?
Can we add duplicate keys in a hashmap?
Is learning data structures necessary?