Starting Out with C++: Early Objects
Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
bartleby

Concept explainers

Question
Book Icon
Chapter 14, Problem 3PC
Program Plan Intro

QuickSort template

Program Plan:

“main.cpp”

  • Include the required header files.
  • Define the main () function.
    • Declare and define the necessary variables using “for” loop.
    • Prompt and get “10” array elements from the user.
    • Call the method “quicksort ()” to perform the sort operation for the given elements.
    • The sorted values are being displayed to the user using “for” loop.

“Quicksort.h”

  • Define the necessary template function.
  • Define the method definition that compare and performs sort operation for the contents of the array using quick sort.
  • Define the  method “swapVars ()” with two arguments,
    • Assign the temporary variable and perform the necessary swap assignment statements as required.
  • Define the method “partition()” with three arguments,
    • Declare the necessary variables.
    • Calculate the “mid” value from the list of elements.
    • Call the function “swapVars ()” to perform necessary swap operations.
    • Use “for” loop to iterate and validate the values using “if” condition then perform the necessary swaps by calling the function “swapVars ()”.
    • Return the index of the pivot element.
  • Define the method “quicksort ()”,
    • Declare the variable named “pivotpt”.
    • Condition statement that compares the values present at the beginning and at the end.
    • Call the method “partition ()” to partition the list.
    • Call the method “quicksort ()” to sort the first and second sub lists.

Blurred answer
Students have asked these similar questions
A "generic" data structure cannot use a primitive type as its generic type. O True False
C language. Function write the arraylist_sort function This generic function sorts an array list using the given compare function. l An array list compare Pointer to the function which compares two elements If you cannot write down a generic function which works for all types, write down a function which sorts resturants. If you cannot use function pointers, you can write down multiple functions which sort using different criteria.
javascript  Define a function, myIncludes, that accepts two parameters: an array and a searchValue. myIncludes should return true if the searchValue is an element in the array. Otherwise, myIncludes should return false.  example  myIncludes([10, 20, 30], 20); // => true myIncludes(['apples', 'bananas', 'citrus'], 'pears'); // => false
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr