## Selection Sort

array int sorta;  // this comes from somewhere only one now!
int sortedIx, searchIx, min, minLoc;
int temp; // add a temporary location for swapping values.

// outer loop over the sorted array -- when everything's sorted we're done
for (sortedIx = 0; sortedIx < sorta.length; sortedIx++) {
// now min is set to the thing in the slot we're currently trying
// to fill.
min = sorta[sortedIx]; minLoc = sortedIx;
// inner loop over messy part of the array: find the smallest number
for (searchIx = sortedIx; searchIx < search.length; searchIx++) {
// if it's the smallest yet seen.
if (sorta[searchIx] < min) {
min = sorta[searchIx];
minLoc = searchIx;
}
} // for searchIx
// move the old value to temp
temp = sorta[sortedIx];
// now stick that small value in the right place
sorta[sortedIx] = min;
// finish the swap
sorta[minLoc] = temp;
} // for sortedIx

## Insertion Sort

array int sorta;  // this comes from somewhere in a messy state
int boundaryIx, searchingIx; // these are indecies
int currentItem // this is the temporary storage for th item we're moving...
// it's old home get's filled with stuff making space for it.

// outer loop over the sorted array -- when everything's sorted we're done
for (boundaryIx gets the values 1 through sorta.length) {
// save new item
currentItem = sorta[boundaryIx]
// inner loop starts at boundary and works down
for (searchingIx = boundaryIx - 1; (sorta[searchingIx] < currentItem) OR
(searchingIx < 0) ; searchIx--) {
// haven't found the right place yet or wouldn't be in here, so
// just move stuff.
sorta[searchingIx+1] = sorta[searchingIx];
} // for searchingIx
// if we're out of the loop, so searchingIx is pointing just neg. of where we want to be
sorta[searchingIx+1] = currentItem;
} // for boundaryIx