how to find the kth smallest element in the given list of
array elemnts.
Answer Posted / khaja moulali shiak
int kmin(int a[],int n,int k)
{
int i;
int j;
int l;
int u;
int x;
int t;
l=1;
u=n;
while(l<u)
{
i=l;
j=u;
x=a[k];
while((i<=k)&&(j>=k))
{
while(a[i]<x) i++;
while(a[j]>x) j--;
swap(a[i],a[j]);
i++;
j--;
}
if(j<k) l=i;
if(i>k) u=j;
}
return(a[k]);
}
| Is This Answer Correct ? | 10 Yes | 6 No |
Post New Answer View All Answers
How can you restore a redirected standard stream?
What is property type c?
What is New modifiers?
Explain how can I manipulate strings of multibyte characters?
What are the modifiers available in c programming language?
What is the use of a static variable in c?
How can I insert or delete a line (or record) in the middle of a file?
What is function definition in c?
How can I pad a string to a known length?
When should a type cast be used?
What is the 'named constructor idiom'?
Can you pass an entire structure to functions?
How can I convert a number to a string?
Explain the red-black trees?
Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)