answersLogoWhite

0

this procedure work for ternary search

int tsearch(int *a,int i,int j,int k)

{

int m1,m2,len;

len = j - i + 1 ;

m1=i + (int)floor((float)(len))/3;

m2=i + (int)ceil((float)(len))/3;

if(k==a[m1])

{

printf("\nno found at %d",m1);

return m1;

}

else if(k==a[m2])

{

printf("\nno found at %d",m2);

return m2;

}

if(len!= 0) {

if(k<a[m1])

return(tsearch(a,i,m1-1,k));

if(k>a[m2])

return(tsearch(a,m2+1,j,k)); }

else

return -1 ;

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

How can you download c compiler?

write a c program to fine largest/smallest of 3no (using ?:ternary operator/conditional operator)


Write a c plus plus program to find the largest among three numbers using ternary operators?

R = (A &gt; B &amp;&amp; A &gt; C) ? A : (B &gt; C) ? B : C; // parentheses not necessary - for clarity only


Best-First Search with C Code?

execution


Write a programme to find greater among two numbers in c plus plus?

You could use an if, but the ternary operator is especially compact for this purpose: result = a &gt; b ? a : b;


How do you write a algorithm for finding maximum of 2 numbers in c?

You can use the ternary operator, in an expression such as: result = a &gt; b ? a : b; This is equivalent to: if (a &gt; b) result = a; else result = b;


What is syntax in c?

syntax is the way you write your code in it defines the meaning of keywords &amp; how to write


What is template in C?

C does not support templates. Templates are supported by C++ and make it possible to write generic code.


What is ternary operation in c language?

exp ? exp : exp


Enumerate the types of selection constructs in c plus plus?

Selection constructs in C++if...elseswitch/caseconditional ternary operator (?:)


Write c code for extened euclid algorithm?

This is a request, not a question.


How can we write a code after main closed in c language?

Register the function(s) containing the code with atexit.


What is Rondo Ternary and Binary form?

In music Binary, Ternary and Rondo are like the layout of a song. So say A represents a verse, B a chorus and C would represent a Bridge! Binary would be A,B (Verse, chorus) Ternary would be A,B,A (Verse, chorus, verse) Then Rondo would be A,B,A,C,A (Verse, chorus, verse, bridge, verse)