So I recently switched from Java to C++ and am building an example of selection sort as a way to get to know the Vector library a little bit better. However, when I try to run the program, there are no build errors but there are two debug errors.
After clicking ignore, I get a ton of warnings like this one:
I am still pretty new to C++ so I have no idea what is causing these errors and any help would be greatly appreciated. Here is the code I have written, thank you in advance. If you would like any more information please ask and I will provide what is needed.
#include <stdlib.h>
#include <vector>
#include <iostream>
using namespace std;
int findLowest(vector<int> in) {
int min = in[0];
int index = 0;
for (int i = 1; i < in.size(); i++) {
if (in[i] < min) {
min = in[i];
index = i;
}
}
return index;
}
void printVector(vector<int> in) {
vector<int>::iterator v = in.begin();
while (v != in.end()) {
cout << *v << endl;
v++;
}
}
vector<int> selectionSort(vector<int> toSort) {
vector<int> temp;
for (int i = 0; i < toSort.size(); i++) {
int tempIndex = findLowest(toSort);
temp.push_back(toSort[tempIndex]);
temp.erase(temp.begin() + tempIndex);
}
return temp;
}
vector<int> randomArray(int size) {
vector<int> temp;
for (int i = 0; i < size; i++) {
temp.push_back(rand() % 100);
}
return temp;
}
void main() {
vector<int> toSort = randomArray(20);
printVector(toSort);
vector<int> sorted = selectionSort(toSort);
printVector(sorted);
cin.ignore();
}