Sorting & Searching

I desperately need help with my homework for my Computer Science class. I'm struggling greatly with this assignment because I really don't understand how to approach this.

So the following is the algorithm for selection sort which should sort the numbers(n) in vector (arr) in non-decreasing order.

1
2
3
4
for (i = 0; i < n-1; i++)
    for (j = i+1; j < n; j++)
        if (arr[i] > arr[j])
            swap(arr[i], arr[j])


I need to implement this into C++ to test for correctness. The main() function I need to make should input a set of numbers from an input file into a vector, call and pass the vector to selection sort, and display the sorted numbers.

I really would appreciate the help on this one since the only advice my professor has offered has been him saying, "If you don't understand then you should just quit." Thank you to anybody who can offer guidance on how to complete my homework.
Oh and if it helps any, the input file I need to use contains the following numbers:

1
2
3
4
5
6
7
8
20
10
5
15
35
40
25
30
1. Declare and open the file
2. Declare an empty vector of ints
3. Read from the file in a loop, and push_back every number read in into the vector.
4. Pass the vector to a selection sort function (which you already seem to have).
5. Pass the vector to a print function, which prints the contents of the vector (now sorted).

Which of these steps are you having trouble with? What is your code so far?
I honestly just needed a step by step process to tackle each thing. I was about to take care of it and the program does exactly what I need it to do! Thank you for the help!
Topic archived. No new replies allowed.