Modify quicksort so that it sorts array in ascending order

Assignment Help Data Structure & Algorithms
Reference no: EM131168830

Programming Assignment-

Instructions:

Consider the following quicksort program and modify it so that it sorts the array in ascending order, uses pointers instead of indexes, and works with vectors.

Test the program on several data input arrays.

//Quick Sort Functions for Descending Order
//From https://mathbits.com/MathBits/CompSci/Arrays/Quick.htm void QuickSort(int * num, int top, int bottom)
{
// top = subscript of beginning of array
// bottom = subscript of end of array

int middle;
if (top < bottom)
{
middle = partition(num, top, bottom); quicksort(num, top, middle); // sort first section
quicksort(num, middle+1, bottom); // sort second section
}
return;
}

//Function to determine the partitions
// partitions the array and returns the middle subscript int partition(int * array, int top, int bottom)
{
int x = array[top]; int i = top - 1;
int j = bottom + 1; int temp;
do
{
do
{
j - -;
}while (x >array[j]);

do
{
i++;
} while (x <array[i]);

if (i < j)
{
temp = array[i]; array[i] = array[j]; array[j] = temp;
}
}while (i < j);
return j; // returns middle subscript
}

Reference no: EM131168830

Questions Cloud

Differences between the house of representatives and senate : Short essay responses should of at least 300 words Please use intro, body and conclusion format. Minimum of 2 sources each for a total of 4. Has to be submitted through turnitin.com for a plagiarism check. What are the differences between the Hous..
Does this filter remove any edges : Does this filter remove any edges that are not removed by vertex-degree filtering?- Does it remove any that are not removed by alldiff filtering?
What is the anticipated stock price at the beginning of 2011 : Justin Cement Company has had the following pattern of earnings per share over the last five years: . Project earnings and dividends for the next year (2011).  If the required rate of return (Ke) is 13 percent, what is the anticipated stock price (P0..
What most important factors in determining why people vote : What are the most important factors in determining why people vote? Are there particular factors that appear to be more important than other factors? Does this hold true for all countries or just the United States?
Modify quicksort so that it sorts array in ascending order : Consider the following quicksort program and modify it so that it sorts the array in ascending order, uses pointers instead of indexes, and works with vectors.
How various explanations are competitive in the literature : How the various explanations are competitive in the literature on the particular case, and how the various causes or different causes of similar or different cases help contribute to the theories and general explanations of WAR.
Describe how to use this oracle : ssume there is an oracle that can quickly tell whether a graph is hamiltonian. - Describe how to use this oracle to check quickly whether a particular edge in a graph is hamiltonian.
Write the resulting benders cut : Suppose that a Benders method is applied to a minimum total tardiness planning and scheduling problem.- Write the resulting Benders cut (3.147).
Draw a graph with five vertices and many edges as possible : [BB] Draw a graph with five vertices and as many edges as possible. How many edges does your graph contain? What is the name of this graph and how is it denoted?

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Find min returns the minimum key in the search tree

Find min returns the minimum key in the search tree, find min obj returns the object belonging to the minimum key,

  Create algorithm to count of integers less than average

Create the algorithm which will prompt for and get 10 integers from the operator at terminal, and then count number of integers whose value is less than average value of integers.

  Pseudocode contains pseudo-code for a program

Pseudocode contains pseudo-code for a program which processes a client file (the master file) and a service file (the transaction file) by updating the clientTotal field in the client file according to the serviceTotal field in the service file.

  Creating sql statements

Create three SQL statements: the 1st statement should add pending amounts to appropriate accounts, the second statement should subtract the pending amounts from appropriate accounts,

  Evaluate algebraic expression by code with three-operand

Evaluate a short algebraic expression using code with three-operand instructions. The expression should have a minimum of three operands and 2 operators.

  Determine order of operations for seq search algorithm

Determine the order of operations for this Seq Search algorithm. Best case and worse case and why - Find the order of operations for this Search algorithm. Prepare a proper algorithm for this problem and how to complete it.

  Describe a polynomial time algorithm

Describe a polynomial time algorithm that solves the following decision problem: Given a graph G and an edge f in it, does G have a cycle containing f?

  Part 1 - report write a 2000-word report that describes a

part 1 - report write a 2000-word report that describes a suitable methodology from the literature for the purpose of

  Design pseudo code for a program that accepts insurance data

Design a flowchart or pseudo code for the A program that accepts insurance policy data, including a policy number, customer last name, customer first name, age, premium due date (month, day, and year), and number of driver accidents in the last thr..

  Write algorithm to calculate the median using queries

Calculate the median using as few queries as possible. Provide an algorithm which determines the median value using at most O(lg n) queries.

  Create algorithm to prepare daily hotel charge report

Create the algorithm to prepare the daily hotel charge report. Input consists of series of records which contain a room number, customer name, cost of the room, and cost of meals charged to the room.

  What steps should you take when designing an adt

What steps should you take when designing an ADT? The following function computes the sum of the first n ≥ 1 integers. Show how this function satisfies the properties of a recursive function.

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