Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using C language. Write a function that implements quickselect to find the k-th smallest element in an array of n elements (1 k n). JUST

using C language. Write a function that implements quickselect to find the k-th smallest element in an array of n elements (1 k n). JUST ONE FUNCTION. NO QUICK SORT int quickselect(int * a, int k, int n)

it has to be work with main function

#include  #include  int quickselect( int *A, int k, int n); int main(void) { long i; int *space; int tmp; space = (int *) malloc( 1000000*sizeof(int)); for( i=0; i< 500000; i++ ) { *(space + i) = ((139*i)%500000); *(space + i + 500000) = 1000000 + ((141*i)%500000); } if( (tmp = quickselect( space, 500001, 1000000)) != 1000000 ) { printf(" Failed test 1. Returned %d instead of 1000000 ", tmp); fflush(stdout); exit(-1); } else printf("passed test1 "); for( i=0; i< 500000; i++ ) { *(space + i) = ((139*i)%500000); *(space + i + 500000) = 1000000 + ((141*i)%500000); } if( (tmp = quickselect( space, 1, 1000000)) != 0 ) { printf(" Failed test 2. Returned %d instead of 0 ", tmp); fflush(stdout); exit(-1); } else printf("passed test2 "); for( i=0; i< 500000; i++ ) { *(space + i) = ((139*i)%500000); *(space + i + 500000) = 1000000 + ((141*i)%500000); } if( (tmp = quickselect( space, 124, 1000000)) != 123 ) { printf(" Failed test 3. Returned %d instead of 123 ", tmp); fflush(stdout); exit(-1); } else printf("passed test3 "); printf("Quickselect successful "); exit(0); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions

Question

=+ 46-2 Discuss how an infant's brain begins processing memories.

Answered: 1 week ago

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

Describe the nature of negative messages.

Answered: 1 week ago