From f53a1593ab4010ce0e724981bf3ef23d1f83cd26 Mon Sep 17 00:00:00 2001 From: DavidG33k Date: Sun, 20 Oct 2019 18:22:23 +0200 Subject: [PATCH] Create selection_sort.cpp Added selection sort algorithm in c++ --- selection_sort_c++/selection_sort.cpp | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 selection_sort_c++/selection_sort.cpp diff --git a/selection_sort_c++/selection_sort.cpp b/selection_sort_c++/selection_sort.cpp new file mode 100644 index 00000000..030c0f29 --- /dev/null +++ b/selection_sort_c++/selection_sort.cpp @@ -0,0 +1,50 @@ +#include +#include +using namespace std; + +void selection_sort(vector seq); + +int main () { + vector seq; + int vector_dim; + int temp; + + cout << "This software sort a vector of integers using selection sort algorithm." << endl; + + cout << "Insert vector dimension: "; + cin >> vector_dim; + + if(vector_dim == 0) { + cout << "Invalid vector dimension" << endl; + return 0; + } + + cout << "Insert numbers separated by space: "; + + for(unsigned i=0; i> temp; + seq.push_back(temp); + } + + selection_sort(seq); +} + +void selection_sort(vector seq) { + for(unsigned i=0; i