Modify it so it gives the ith largest number

Assignment Help C/C++ Programming
Reference no: EM13163684

the follow code gives the ith smallest number, how do you modify it so it gives the ith largest number ?

 

int random_selection(int* arr, int start, int end, int k)

{

if(start == end)

return arr[start];

 

if(k ==0) return -1;

 

if(start < end)

{

 

int mid = random_partition(arr, start, end);

int i = mid - start + 1;

if(i == k)

return arr[mid];

else if(k < i)

return random_selection(arr, start, mid-1, k);

else

return random_selection(arr, mid+1, end, k-i);

}

 

}

 

 

Reference no: EM13163684

Questions Cloud

Compare the athlete''s time of each event : The class should have static data members of 60 minutes. This is the maximum time of any one event. Compare the Athlete's time of each event to the static data member. If the athlete's time exceeds the 60 minutes, output a message that they are di..
Compute the average grades : Write a program that allows a teacher to compute the average grades for EACH student in his or her class (NOT a single average for the entire class)
Averages ten homework grades entered : Write a program that averages ten homework grades entered by the user. Allow for a bonus homework grade that can count as 5 extra points on their average. Create at least two functions (excluding main() ) in your program. In the first function, pr..
Generates all the possible n-node binary tree configurations : Implement a function that generates all the possible N-node binary tree configurations. The value N is a parameter to the function and the function should return a list of binary tree. Any container ADT (list, queue, vector, etc...) can be used to st..
Modify it so it gives the ith largest number : the follow code gives the ith smallest number, how do you modify it so it gives the ith largest number ?
Write a mips assembly language program : Write a MIPS assembly language program that prompts for a user to enter a series of floating point numbers and calls read_float to read in numbers and store them in an array. Then the program should display the array content on the console window. Th..
Program that will accept a real number : Create a program that will accept a real number from the user and then display its whole and fractional parts. (For example, if the input is 5.32, the outputs should be the integer value
Discuss the concept of phase shift in oscillators : Discuss the concept of phase shift in oscillators and how it is controlled in oscillator circuits.
What resources are available on the internet : What resources are available on the Internet to help system administrators determine how to harden a Windows Server 2008? Windows 7 workstation? (List at least three resources in your response.)

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Maze program

Maze program. In this assignment you will represent a maze with a binary tree. . The starting point is node N and the ending point is node Z.

  An integer on this system is 4 bytes long

Assume the following for the program below. An integer on this system is 4 bytes long. The memory address where the array "a[]" was created begins at location 8000. a. #include

  Squares, triangles, circles and ellipses

write a program which will answer a pair of questions for squares, triangles, circles and ellipses. A square is defined by its lower left corner ( S L L x , S L L y ), and the length of one side  S W .

  Define a structure to store marks of a student

Define a structure to store roll no, name and marks of a student - using the structure of Q2. a), above write a 'C' program to create a file "student.dat". There must be one record for every student in the file.

  Const int num_years

How do you get this program to get both player input and then display results(As described on bottom) #include  const int NUM_YEARS=15;//The number of years const int NAME_SIZE=32;//The max size of the player name string

  Draw the heap

Eric Rowe Starting with an empty minheap, draw the heap after each the completion of the following operations  and repeat for a maxheap (replace removeMin() with removeMax()). Upload your drawings here. Hand drawn is fine:

  Write program which reads n numbers from keyboard

Write down C++ program which reads N numbers (positive, negative, integer and double numbers) from keyboard, computes and shows the following information. Largest number of all numbers entered from keyboard.

  Write a program that will be used to gather statistical data

Write a program that will be used to gather statistical data about the number of movies

  Write c program to add two integers and prints out average

Write a C program that prompts for a variable number of integers, adds them up, and prints out the average. The user will enter either an integer to be averaged.

  Multiple choice question on c programming

Create a function to print "88 is a great port number" function name is yourName_PrintFunction no input no return type print "88 is a great port number"

  Create a website that would allow users to enter and submit

Create a Website that would allow users to enter and submit survey

  Least number of comparisons needed

What is the least number of comparisons needed to sort an array of 6 numbers, in the worst case, using any sorting algorithm that sorts with binary comparisons? Explain

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd