-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStdSort.cpp
30 lines (26 loc) · 1014 Bytes
/
StdSort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* CSCI 335 Project 3
* Spring 2024
* Created by Allison Lee
*/
#include <algorithm>
#include "StdSort.hpp"
/**
* std::sort is called and prints out the appropriate data points via direct access.
* This is used to ensure the correct answer and printing, and to give a baseline to time other algorithms against.
* @param: string header is the first line of the input file
* @param: data is a vector of integers converted from the input file
*/
void stdSort(const std::string& header, std::vector<int> data){
std::sort(data.begin(), data.end());
// get indices of median, p25, and p75
int median_index = (data.size())/2 - 1;
int p25_index = (median_index)/2;
int p75_index = (median_index + data.size())/2;
std::cout << header
<< "\nMin: " << data[0]
<< "\nP25: " << data[p25_index]
<< "\nP50: " << data[median_index]
<< "\nP75: " << data[p75_index]
<< "\nMax: " << data[data.size() - 1] << std::endl;
}