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
What is the difference between 1d and 2d array?
What is the use of prototype?
Are the expressions arr and &arr same for an array of integers?
What is modcount in hashmap?
Define dynamic data structures?
Why null is allowed in hashmap?
What is bubble sort algorithm?
Explain pre-order and in-order tree traversal.
Why we need cursor implementation of linked lists?
What is data and its type?
Mention for which header list, you will found the last node contains the null pointer?
List the area of applications where stack data structure can be used?
What is the difference between hashset and arraylist?
Is hashmap get thread safe?
Define the queue data structure.