Intro to Computer Science (c++)
Intro to Computer Science (c++)
Write a bubble sort function that sorts an std::vector of integers.
Write a selection sort function that sorts an std::vector of integers.
The signature of your sort functions should/must be:Â SortStats bubbleSort(std::vector& sortVector)
Report timing on vectors (of random integers)Â of size 100 to 1000, stepping by 100, how long it takes the bubble and selection sort functions. Â This means you need
to write a function that accepts a parameter of how many items to place into a vector, generate that vector, and return it from the function.
Remember to create one vector for the bubble sort and a different vector for the selection sort. Â If you don’t, the selection sort will be sorting an already sorted
vector.
The provided example timing.cppPreview the documentView in a new window includes code that demonstrates the timing of how long a function takes to execute.  You’ll
need to use this code/pattern in your assignment. Â This code will be reviewed in class so you can better understand what it is doing and how to use it in your code.
Your output should look like the following…
— Timing Results —
Number of items : 100
Bubble sort time : 1.7777e-05 seconds
Selection sort time : 9.195e-06 seconds
Number of items : 200
Bubble sort time : 6.9882e-05 seconds
Selection sort time : 2.6666e-05 seconds
Number of items : 300
Bubble sort time : 0.000169801 seconds
Selection sort time : 5.517e-05 seconds
Number of items : 400
Bubble sort time : 0.00032397 seconds
Selection sort time : 8.9191e-05 seconds
Number of items : 500
Bubble sort time : 0.000503579 seconds
Selection sort time : 0.000136393 seconds
Number of items : 600
Bubble sort time : 0.000729162 seconds
Selection sort time : 0.00019003 seconds
Number of items : 700
Bubble sort time : 0.00101114 seconds
Selection sort time : 0.000255621 seconds
Number of items : 800
Bubble sort time : 0.00131243 seconds
Selection sort time : 0.000331939 seconds
Number of items : 900
Bubble sort time : 0.00168789 seconds
Selection sort time : 0.000413468 seconds
Number of items : 1000
Bubble sort time : 0.0020278 seconds
Selection sort time : 0.000500207 seconds
Test Cases
You are provided test cases that help you know if your code is correct.
testCase1: Tests the sort function on a vector of 10 items.
testCase2: Tests the sort function on a vector of 500 items.
testCase3: Tests the sort function over vectors ranging in size from 100 to 1000 items.
testCaseCompare: Compares the results of the bubble and selection sorts to verify the selection sort has better performance in terms of swaps and time.
The test cases expect the sorting functions to accept a reference to a vector of integers and return a structure called SortStats. You can find this structure defined
in a file named SortStats.hppPreview the documentView in a new window. In addition to sorting the data in the vector, you need to track how many comparisons and swaps
were performed, recording them into the members of this structure.
You can use this same SortStats structure for reporting the timing information described in the main part of the assignment. While running the test cases, if you
notice timing discrepancies, then try building in release mode. For GCC, this involves adding optimizations via the ‘-O#’ argument where # is a number indicating the
level.
Provided code: main.cppPreview the documentView in a new window SortStats.hppPreview the documentView in a new window SortStats.cppPreview the documentView in a new
window TestCases.hppPreview the documentView in a new window TestCases.cppPreview the documentView in a new window timing.cppPreview the documentView in a new window
