> function named selectionSort. (...) I'll be honest, I don't really understand
> the bubble sort algorithm very well
¿do you want «selection sort» or «bubble sort»?
selection sort:
Say that you want to sort the elements of container `A'
Create an empty container `B'. At the end of the algorithm, B will be sorted.
At each step you remove the smallest element from `A' and put it at the end of B.
Repeat until `A' is empty.
note that at each step the element extracted is bigger than the last one, so putting it at the end of B would give you the sequence sorted.
(it may be implemented with only one container, but I think this one may be easier to understand)
bubble sort:
at each step you traverse the container comparing two adjacent elements, if they are not in order (the left is bigger than the right) you swap them.
repeat until `A' is sorted.
note that each swap would fix the relative order of two elements. So after comparing all against all, the container would end sorted.
After you understand the algorithm, let's talk about the implementation.
> it is my intent to use pointers to access the array "rents" (...)
> nor do I have a very good grasp on pointers yet.
lets leave that for later. Do it with array notation if you find it easier.
I guess that you don't intend to translate
v[K] -> *(v+K)
, but threat it as forward iterators.
To traverse a container
1 2 3 4 5 6 7
|
//range [)
int *begin = array;
int *end = array+size;
for(int *current = begin; current not_eq end; ++current){
//...
}
|
++current
would be «advance to the next element»
*current
would be «access the element»