I learned a little with starting c++ this semester, so I thought is it possible to combine vector array and the selectionSort function,so I built the program with vector arrays first through user input, asking for size and then asking user to input values. It worked fine. So I thought try and use the function selectionSort bypassing the for loops manually. It won't sort the data input so maybe I should just build or write the selection sort from scratch.
I would like to know why it won't sort.
Any brutal comments are welcome as well.. thanks .. when I added the sortedData and selectionSort it did not sort but compiled though Dev c++comp used
The vector is passed by value to the function. That means that inside the function a is a copy of the vector passed in so any changes to a will only affect the copy.
If you want the function to change the vector you give to it you can pass the vector by reference. void selectionSort(vector<int>& a,int)
It is generally a good idea to always pass vectors by reference to avoid expensive copying. If the function doesn't change the vector you can pass a const vector. void showData(const vector<int>& vect)
Thank Peter87, that explains, the address and pointer differences when used.
I overlooked the syntax for sortSelection( func) that it had this in the syntax..
hm.. what would you suggest in learning how to be more proficient in loops as used
in sorting and swapping just on a general basis or wide applications..
The code below was what I initially started before I did the vector version still I think
I need to build more codes from scratch I only learned basic, pascal when I was 19..
C++, I encountered only now that I'm 32.. lol thanks though..