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

  Write a menu-driven program that maintains an address book

Write a menu-driven program that maintains an address book using a linked list. The address book must supports the following operations

  Define two derived classes of the abstract class

Define two derived classes of the abstract class ShapeBase below. Your two classes will be called RightArrow and LeftArrow. These classes will draw arrows that point right and left,

  Write a c function void print_triangle(int n)

Write a C function void print_triangle(int n) that prints a triangular pattern of asterisks of height n and width 2 * n + 1 with one asterisk in the first line, three in the second line, etc.,

  Grocery store program

This program draws upon several concepts that were covered in CptS 121 and should serve as a good refresher for CptS 122. Our store, Cougar Mart, maintains its inventory in a text file. Not being very tech savvy, the owner of Cougar Mart needs you to..

  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.

  Write c++ programs

Write a C++ program to accept distance in kilometers, coverts it to meters and then displays the result. Write a C++ program to find area and circumference of a circle.

  Implement the tronomino tiling algorithm

Implement the tronomino tiling algorithm,  our program should take an arbitrary input positive integer  k  in the Linux command line and generate a 2 k  * 2 k  board.

  Write the class definition for a class called complex

. Write the class definition for a class called complex.

  Give students practice in writing and calling their function

To give students practice in writing and calling their own functions. To give students practice in implementing and planning complex programs.

  Program to generate 100,000 prime numbers

Write a POSIX C/C++ program to generate 100,000 prime numbers. Assume that the program will be run on a computer with 5 CPUs and that your goal is to have this program finish as quickly as possible.

  Write a c function to convert gallons-quarts-pints and cups

Write a C function named liquid() that is to accept an integer number and the addresses of the variables gallons, quarts, pints, and cups.

  Define a class called plot that has private members of lengt

Define a class called Plot that has private members of length and width. Include a constructor and a public function that calculates the area and the length of the boundary of the field.

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