You are going to compare the number of basic operations and the number
of assignment of records to perform the sort.
- #include iostream
- #include cassert
- #include fstream
- #include string
You may not use the standard template library or any vector libraries. All code must be written by you.
heapsort, mergesort, and quicksort
As stated above, implement heapsort quicksort, and mergesort from your textbook.
Six Global Variables: It is easiest if you use six, and only six,global variables:
- Count the number of basic operations in heapsort
- Count the number of assignments of records in heapsort
- Count the number of basic operations in mergesort
- Count the number of assignments of records in mergesort
- Count the number of basic operations in quicksort
- Count the number of assignments of records in quicksort
Basic Operations and assignment of Records
In the analysis of each of the sorting routines provided by your text, the
basic operation used for analysis is defined.
- Heapsort: comparison of keys in softdown
- Mergesort: comparison of U[i] and V[j] in merge
- Quicksort: comparison of S[i] with pivotitem
Every time a record from the array is assigned as part of the sort, you must count
the assignment. Look at this very carefully. For example, an exchange is three assignments.
The main program
Declare arrays for data to be heapsorted, mergesorted, and quicksorted.
You can declare the
arrays to be of size 600. If a file contains >512 records, truncate it.
- Prompt the user for the name of a file. Open the file. Use assert to ensure the file opened
- Read the contents of the file. You can assume it contains valid integer data
You do not have to validate it. Store each data
element into the array declared for heapsort, the array declared for mergesort,
and the array declared for quicksort.
- Print one of the arrays
- Print the array sorted by heapsort, mergesort, and quicksort properly labeled.
- Print n, the number of basic operations for each sort, and the number of assignments of records for each sort.
Submission
Use turnin to submit your program. Select sorting. Your filename should be
sort.cpp.
Submit your analysis in D2L.
Last Modified
8:41 PM 06/17/2022
This is © copyright protected by Barbara Bracken