Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

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

Quick sort template

Program Plan:

Main.cpp

  • Include the required header files.
  • Declare the necessary function prototype and constants.
  • Define the main () function.
    • Declare the necessary variables.
    • Get the required input 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 a loop.

Quicksort.h

  • Define the template function necessary.
  • Define the method definitions that compares and performs sort operation for the contents of the array using quick sort.
  • Define the method “quickSort()”,
    • Declare the necessary variables.
    • 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.
  • Define the method “partition()”,
    • Declare the necessary variables.
    • Calculate the mid value of the list.
    • Call the function to perform necessary swap using “swapVars()”.
    • Use a loop to iterate to 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 “swapVars()”,
    • Declare the necessary variables.
    • Assign the temporary variable and perform the necessary swap assignment statements as required.

Blurred answer
Students have asked these similar questions
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.
flip_matrix(mat:list)->list You will be given a single parameter a 2D list (A list with lists within it) this will look like a 2D matrix when printed out, see examples below. Your job is to flip the matrix on its horizontal axis. In other words, flip the matrix horizontally so that the bottom is at top and the top is at the bottom. Return the flipped matrix. To print the matrix to the console:  print('\n'.join([''.join(['{:4}'.format(item) for item in row]) for row in mat])) Example: Matrix:
W R I T X
H D R L G
L K F M V
G I S T C
W N M N F
Expected:
W N M N F
G I S T C
L K F M V
H D R L G
W R I T X Matrix:
L C
S P
Expected:
S P
L C Matrix:
A D J
A Q H
J C I
Expected:
J C I
A Q H
A D J
A "generic" data structure cannot use a primitive type as its generic type. O True 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++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr