Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a sorting function that will sort a vector of ints. Use the selection sort

ID: 662687 • Letter: W

Question

Write a sorting function that will sort a vector of ints. Use the selection sort algorithm. The sort function should have the following declaration:

Note: the function should have one parameter, it does not need a size parameter since vectors know their own size.

Write a program that inputs a sequence of integers (ending with an empty line) and prints the resulting sorted vector all on one line with elements separated by commas.

A session should look like one of the following examples (including whitespace and formatting), with possibly different numbers in the output:

**************************************************************************************************************************************************************************************************************************************************************IMPORTANT: The strings printed by the program should include a newline at the end, but no other trailing whitespace (whitespace at the end of the line).

**************************************************************************************************************************************************************************************************************************************************************

Explanation / Answer

01: #include 02: #include 03: #include 04: #include 05: 06: using namespace std; 07: 08: /** 09: Swaps two integers. 10: @param x the first integer to swap 11: @param y the second integer to swap 12: */ 13: void swap(int& x, int& y) 14: { 15: int temp = x; 16: x = y; 17: y = temp; 18: } 19: 20: /** 21: Gets the position of the smallest element in a vector range. 22: @param a the vector 23: @param from the beginning of the range 24: @param to the beginning of the range 25: @return the position of the smallest element in 26: the range a[from]...a[to] 27: */ 28: int min_position(vector& a, int from, int to) 29: { 30: int min_pos = from; 31: int i; 32: for (i = from + 1; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote