#include #include #include //has stuff to time code using namespace std; //Print all items in array nums from start to end void printItems(double nums[], int start, int end) { for (int i=start; i<=end; i++) { cout << nums[i] << endl; } } //Return the index of the smallest item in the array //from start to end //Run time: O(n) (n steps to solve this problem) int locateSmallest(double nums[], int start, int end) { //Oh no! Someone accidently deleted the code! //You'll have to rethink about how to do it //for lab! } //Rearrange items in array from start to end //into sorted order. //Selection Sort //Run time: O(n^2) steps void sort(double nums[], int start, int end) { for (int i = start; i <= end; i++) //loops n times { //Oh no! Someone accidently deleted the code! //You'll have to rethink about how to do it //for lab! } } int main() { //Quiz: Write a locateSmallest function. //Submit to blackboard by 12:40. double numbers[] = { 52, 17, 38, 58, 1238, 4, 13, 53, 12 ,85, 11, 388, 3, 0, 19 }; //locate smallest should return the index //of the smallest number in the array //between the given range (inclusive) //cout << locateSmallest(numbers, 0, 14) << endl; // 13 //cout << locateSmallest(numbers, 5, 8) << endl; // 5 //Next: can you sort the array? //sort(numbers, 0, 14); //printItems(numbers, 0, 14); //Let's stress test our sorting algorithm int size = 100000; double* bigNums = new double[size]; //fille randomnly for (int i = 0; i < size; i++) { bigNums[i] = rand(); } //sort them! auto start = chrono::high_resolution_clock::now(); sort(bigNums, 0, size - 1); auto finish = chrono::high_resolution_clock::now(); chrono::duration elapsed = finish - start; cout << "Selection sort took: " << elapsed.count() << endl; //printItems(bigNums, 0, size - 1); return 0; } //Code to time stuff: // //auto start = chrono::high_resolution_clock::now(); //auto finish = chrono::high_resolution_clock::now(); //chrono::duration elapsed = finish - start; //elapsed.count()