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
What are header files in c?
A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference
What is the difference between Printf(..) and sprint(...) ?
When was c language developed?
What is the maximum length of an identifier?
Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same.
How can I prevent another program from modifying part of a file that I am modifying?
In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.
int i=10; printf("%d %d %d", i, i=20, i);
What is the difference between struct and union in C?
What are structure members?
What is #error and use of it?
Explain do array subscripts always start with zero?
What is substring in c?
Why is not a pointer null after calling free?