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++ Progrmaing Instructions Redo Programming Exercise 6 of Chapter 8 using dynamic arrays. The instructions have been posted for your convenience. The history teacher at your school needs help in grading a True/False test. The students’ IDs and test answers are stored in a file. The first entry in the file contains answers to the test in the form: TFFTFFTTTTFFTFTFTFTT Every other entry in the file is the student ID, followed by a blank, followed by the student’s responses. For example, the entry: ABC54301 TFTFTFTT TFTFTFFTTFT indicates that the student ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is False, and so on. This student did not answer question 9 (note the empty space). The exam has 20 questions, and the class has more than 150 students. Each correct answer is awarded two points, each wrong answer gets one point deducted, and no answer gets zero points. Write a program that processes the test data. The output should be the student’s ID,…
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