When you become a mature programmer working on a huge project:Consider the following scenario:
|
|
vector programvector program contains two cpp files and some h files.
|
|
|
g++ -c point.cppThe above command will create an object file
point.o .
g++ -c main.cppThe above command will create an object file
main.o .
g++ point.o main.o -o vectorThen, when the program is linked, these two compiled pieces (i.e., object files) are brought together (along with any standard library code we need) to form a complete program.
Write a program that reads in the numbers and output them in increasing order.
$ ./a.out N = 4: 7 4 1 3 1 3 4 7 $ ./a.out N = 7: 100 -7 3 9 12 -6 45 -7 -6 3 9 12 45 100You are given the easy part on the right. Write the function sort()
|
|
I hope the following picture clarifies the idea behind Selection Sort algorithm.
| data = 7, 4, 1, 3 iteration 0 | sorted up to index 0 iteration 1 | sorted up to index 1 iteration 2 | sorted up to index 2 (actually, all sorted) |
# # # put # # the smallest # # # at index 0 # # # # # # # (swap 2 -> 0) --------- 0 1 2 3 |
#
#
# put
# # the next smallest
# # # at index 1
# # #
# # # # (swap 3 -> 1)
---------
0 1 2 3
|
#
#
# put
# # the next smallest
# # # at index 2
# # #
# # # # (swap 3 -> 2)
---------
0 1 2 3
|
#
#
#
# #
# # #
# # #
# # # #
---------
0 1 2 3
|