Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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.
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
Programming Language: C++
I need the codes for arrayListType.h, main.cpp, myString.cpp, myString.h
Chapter 14 Solutions
Starting Out with C++: Early Objects (9th Edition)
Ch. 14.1 - What is a recursive functions base case?Ch. 14.1 - What happens if a recursive function does not...Ch. 14.1 - Prob. 14.3CPCh. 14.1 - What is the difference between direct and indirect...Ch. 14 - What type of recursive function do you think would...Ch. 14 - Which repetition approach is less efficient; a...Ch. 14 - When should you choose a recursive algorithm over...Ch. 14 - Prob. 4RQECh. 14 - Prob. 5RQECh. 14 - Prob. 6RQE
Ch. 14 - Predict the Output 7. What is the output of the...Ch. 14 - Soft Skills 8. Programming is communication; the...Ch. 14 - Prob. 1PCCh. 14 - Recursive Conversion Convert the following...Ch. 14 - Prob. 3PCCh. 14 - Recursive Array Sum Write a function that accepts...Ch. 14 - Prob. 5PCCh. 14 - Recursive Member Test Write a recursive Boolean...Ch. 14 - Prob. 7PCCh. 14 - Prob. 8PCCh. 14 - Ackermanns Function Ackermanns function is a...Ch. 14 - Prefix to Postfix Write a program that reads...Ch. 14 - Prob. 11PCCh. 14 - Prob. 12PC
Knowledge Booster
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
- C++ Format Please Write a function (named "Lookup") that takes two const references to vectors. The first vector is a vector of strings. This vector is a list of words. The second parameter is a list of ints. Where each int denotes an index in the first vector. The function should return a string formed by concatenated the words (separated by a space) of the first vector in the order denoted by the second vector. Input of Test Case provided in PDF:arrow_forwardBy pythonarrow_forwardProblem DNA: Subsequence markingA common task in dealing with DNA sequences is searching for particular substrings within longer DNA sequences. Write a function mark_dna that takes as parameters a DNA sequence to search, and a shorter target sequence to find within the longer sequence. Have this function return a new altered sequence that is the original sequence with all non-overlapping occurrences of the target surrounded with the characters >> and <<. Hints: ● String slicing is useful for looking at multiple characters at once. ● Remember that you cannot modify the original string directly, you’ll need to build a copy. Start with an empty string and concatenate onto it as you loop. Constraints: ● Don't use the built-in replace string method. All other string methods are permitted. >>> mark_dna('atgcgctagcatg', 'gcg') 'at>>gcg<<ctagcatg' >>> mark_dna('atgcgctagcatg', 'gc')…arrow_forward
- Domino cycledef domino_cycle(tiles):A single domino tile is represented as a two-tuple of its pip values, such as (2,5) or (6,6). This function should determine whether the given list of tiles forms a cycle so that each tile in the list ends with the exact same pip value that its successor tile starts with, the successor of the last tile being the first tile of the list since this is supposed to be a cycle instead of a chain. Return True if the given list of domino tiles form such a cycle, and False otherwise. tiles Expected result [(3, 5), (5, 2), (2, 3)] True [(4, 4)] True [] True [(2, 6)] False [(5, 2), (2, 3), (4, 5)] False [(4, 3), (3, 1)] Falsearrow_forwardflip_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 Jarrow_forwardErlang File -module(exam). -compile(export_all). -include_lib("eunit/include/eunit.hrl"). Part A Implement a function called min which takes a tuple of two numeric values and returns the lower value of the two.Implementation notes:• If needed, use Erlang function guards• Do NOT use the if or case structuresSample calls:> exam:min({3, 4}).3> exam:min({4, 3}).3arrow_forward
- CLASSES, DYNAMIC ARRAYS AND POINTERS Define a class called textLines that will be used to store a list of lines of text (each line can be specified as a string). Use a dynamic array to store the list. In addition, you should have a private data member that specifies the length of the list. Create a constructor that takes a file name as parameter, and fills up the list with lines from the file. Make sure that you set the dynamic array to expand large enough to hold all the lines from the file. Also, create a constructor that takes an integer parameter that sets the size of an empty list. in C++ Write member functions to: remove and return the last line from the list add a new line onto the end of the list, if there is room for it, otherwise print a message and expand the array empty the entire list return the number of lines still on the list take two lists and return one combined list (with no duplicates) copy constructor to support deep copying remember the destructor!arrow_forwardRemove is a function that has been defined.arrow_forwardC++arrow_forward
- Homework Assignment-1Topics: Functions, Dictionary, ImportProblem description: Write a python application to simulate an online clothing system. Thepurpose of this assignment is to gain experience in Python dictionary structure, create basicPython functions and import a module.Design solution: The template file contains a list of clothes item sold, each item in the listcontains the item id, name of the item and the prices. The program will generate an items_dictwhere each key is the item id of the cloth and the values will be a list of item name and priceinformation. A customer will be presented with a main menu with 4 different options: displayall items, add an item to cart, checkout and exit the program. A customer can buy an item byentering the ID of the item. This program implements a dictionary called cart, where each key isthe item id and the values are the list of name, price and quantity that user chooses topurchase. The program keeps repeating by displaying the main menu to…arrow_forwardExercise, maxCylinderVolume F# system function such as min or methods in the list module such as List.map are not allowed Write a function maxCylinderVolume that takes a list of floating-point tuples that represent dimensions of a cylinder and returns the volume of the cylinder that has the largest volume. Each tuple has two floating point values that are both greater than zero. The first value is the radius r and the second value is the height h. The volume of the cylinder is computed using ??2h. The value π is represented in F# with System.Math.PI. If the list is empty, return 0.0. Examples: > maxCylinderVolume [(2.1, 3.4); (4.7, 2.8); (0.9, 6.1); (3.2, 5.4)];;val it : float = 194.3137888> maxCylinderVolume [(0.33, 0.66)];;val it : float = 0.2257988304arrow_forwardWrite a template for a function that displays the contents of an array of any data type.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr