Starting Out With C++: Early Objects (10th Edition)
Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
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
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.
Concatenate Map This function will be given a single parameter known as the Map List. The Map List is a list of maps. Your job is to combine all the maps found in the map list into a single map and return it. There are two rules for addingvalues to the map. You must add key-value pairs to the map in the same order they are found in the Map List. If the key already exists, it cannot be overwritten. In other words, if two or more maps have the same key, the key to be added cannot be overwritten by the subsequent maps.   Signature:   public static HashMap<String, Integer> concatenateMap(ArrayList<HashMap<String, Integer>> mapList) Example: INPUT: [{b=55, t=20, f=26, n=87, o=93}, {s=95, f=9, n=11, o=71}, {f=89, n=82, o=29}]OUTPUT: {b=55, s=95, t=20, f=26, n=87, o=93} INPUT: [{v=2, f=80, z=43, k=90, n=43}, {d=41, f=98, y=39, n=83}, {d=12, v=61, y=44, n=30}]OUTPUT: {d=41, v=2, f=80, y=39, z=43, k=90, n=43} INPUT: [{p=79, b=10, g=28, h=21, z=62}, {p=5, g=87, h=38}, {p=29,…
Programming Language: C++ I need the codes for arrayListType.h, main.cpp, myString.cpp, myString.h
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