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
How does linkedhashset work internally?
What is linked list in data structure?
What are the 3 types of measurement?
What are the advantage of linked list over array?
How do you sort elements in an arraylist?
Write the procedure to convert general tree to binary tree?
How would you swap the Kth node from beginning with Kth node from end in a Linked List.
Define double hashing?
Is null a binary search tree?
How do we find duplicate elements in an array?
What are the categories of avl rotations?
Differentiate between list and map.
Which programming language is best for data structures?
In depth questions regarding the data structures and the Databases used in the Projects developed.
Does arraylist have a tostring?