-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort.cpp
44 lines (38 loc) · 1.03 KB
/
sort.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// sort.cpp
// CS2Final
//
// Created by Samantha-Jo Cunningham on 5/7/18.
// Copyright © 2018 Samantha-Jo Cunningham. All rights reserved.
//
#include <stdio.h>
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include<iomanip>
#include "sort.h"
using namespace std;
Sort::Sort(){}
void Sort::SelectionSort(vector <int> PlaylistVect) {
int i;
int j;
int temp;
int indexSmallest;
int VectSize = PlaylistVect.size();
cout << "*** SELECTION SORT ***" << endl << endl;
for (i = 0; i < VectSize; ++i) {
// Find index of smallest remaining element
indexSmallest = i;
for (j = i + 1; j < VectSize; ++j) {
if ( PlaylistVect.at(j) < PlaylistVect.at(indexSmallest) ) {
indexSmallest = j;
}
}
//Swap PlaylistVect.at(i) and PlaylistVect.at(indexSmallest)
temp = PlaylistVect.at(i);
PlaylistVect.at(i) = PlaylistVect.at(indexSmallest);
PlaylistVect.at(indexSmallest) = temp;
}
}
Sort::~Sort(){}