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
Question
Book Icon
Chapter 15, Problem 2PC
Program Plan Intro

Analysis of Quicksort

Program Plan:

  • Include the required header files to the program.
  • Define “AbstractSort” class.
    • In public, declare the pure virtual function.
      • In the “get_comparison” function return the total number of comparison.
    • In protected, declare the “compare” function.
      • In the “reset_comparison” function reset the comparison value to “0”.
    • In private, declare the required variable.
  • Define the “compare” function outside the class definition.
    • Inside the function, increment the comparison count and return the number of comparison.
  • Define the derived class “Quicksort”.
    • In public, declare the “sort” function.
    • In private, declare the “quick” function and “partition” function.
  • Define the “quick” function.
    • If the least number is greater than the highest number, return the value to the function.
    • Call the “partition”, quick” functions.
  • Define the “partition” function.
    • Set the pivot value.
    • Declare and set the “front” variable.
    • If the “front” value is less than “u”, swap the values and increment the pivot variable.
    • Increment the “front” variable.
  • Define the “main()” function.
    • Declare and initialize the required variables.
    • Get the array value from the user.
    • Check the array value with array index.
      • If the array value is greater than index value exits the program.
    • Initialize the random number generator and generate the random numbers.
    • Create the object for the class “Quicksort”.
    • Call the “sort” function.
    • Display the result.

Blurred answer
Students have asked these similar questions
Course: Data Structure and Algorithms Language: C++ Question is well explained   Question #2Implement a class for Circular Doubly Linked List (with a dummy header node) which stores integers in unsorted order. Your class definitions should look like as shown below: class CDLinkedList;class DNode {friend class CDLinkedList;private int data;private DNode next;private DNode prev;};class CDLinkedList   {private:DNode head;                          // Dummy header nodepublic CDLinkedList();            // Default constructorpublic bool insert (int val);       public bool removeSecondLastValue ();                    public void findMiddleValue();                  public void display();                       };
python assignment  Matrix class Implement a matrix class (in matrix.py).  a) The initializer should take a list of lists as an argument, where each outer list is a row, and each value in an inner list is a value in the corresponding row.  b) Implement the __str__ method to nicely format the string representation of the matrix: one line per row, two characters per number (%2d) and a space between numbers. For example: m = Matrix([[1,0,0],[0,1,0],[0,0,1]]) print(m)> 1  0  0> 0  1  0> 0  0  1 c) Implement a method scale(factor) that returns a new matrix where each value is multiplied by scale. For example: m = Matrix([[1,2,3],[4,5,6],[7,8,9]])n = m.scale(2)print(n)> 2  4  6> 8 10 12>14 16 18print(m)> 1  2  3> 4 5 6> 7 8 9 d) Implement a method transpose() that returns a new matrix that has been transposed. Transposing flips a matrix over its diagonal: it switches rows and columns. m = Matrix([[1,2,3],[4,5,6],[7,8,9]])print(m)> 1  2  3> 4 5 6> 7 8…
Y3 Using C++   To test your understanding of recursion, you are charged with creating a recursive, singly linked list. You will need to make the class yourself for this data structure. This repository already contains the List ADT and a driver that will create a TUI (terminal user interface) program that uses your data structure to generate a recursive art animation. Submissions that do not compile will receive a zero. You can work on this by yourself or with one other person. LinkedList This class will represent the data structure. Since we want this data structure to be generic, you need to make it a class template. Create two files for this class: a header file (LinkedList.hpp) and an implementation file (LinkedList.tpp). Place these two files in the src directory. It needs to inherit from the List abstract class using the public access specifier. The following are implementation notes for the class. The majority of methods need to be recursive and optimized via tail recursion…

Chapter 15 Solutions

Starting Out With C++: Early Objects (10th Edition)

Knowledge Booster
Background pattern image
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