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

  Huffmancodes

You will turn in one file: HuffmanCodes.java, which can encode and decode files using Huffman codes. The program has the following command-line interface:

  Auditing focuses on failures

Under normal situations, auditing focuses on failures to access rather than successful accesses. Explain why it might be a good concept to audit successful access to documents in a directory that contains highly confidential documents.

  Display rep and contact as the headings in the two columns

Display Rep and Contact as the headings in the two columns of concatenated field data.

  Data systems and design

Suppose if you have a program with a housekeep() module, a mainloop() module, and a finishup() module, when is the second input record usually read?

  Draw a flowchart of the function realizing insertion sort

Write the corresponding MATLAB code. You should check (just for yourself) how your function works with an arbitrary unsorted array.

  Execute the given stack operation

For each part of this problem, assume the "before" values when the given instruction is executed. Give the requested "after" values.

  Q1 compare the average behavior of insertion sort for n

q1 compare the average behavior of insertion sort for n elements with that of the n insertions into an initially-empty

  Identify the number of odd vertices

identify the number of odd vertices.

  Implement a method to delete every node from your bst

Implement a method to delete every node from your BST that contains a word that is 3 or fewer letters long (note that you must explicitly make these deletions, not fail to insert these words in the first place).

  Solve the following maze with the algorithm

Solve the following maze with the algorithm of your choice. The idea is to come up with a fully automated method to find the shortest path from S to E using minimum number of movements.

  Create unix shell scripts using dos commands

Suppose you are an experienced DOS programmer and you wish to create UNIX shell scripts using DOS commands.

  An undirected graph g is called bipartite

An undirected graph G is called bipartite if its vertices can be partitioned into two sets X and Y such that every edge in G has one end vertex in X and one end vertex in Y

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