I see a few problems with the sorting algorithm:
int p = o - 1;
When the loop first starts, o is 0, but the next thing the code does is compare values[p] with values[p + 1]. That's the same as saying values[-1] > values[0] , which is an out of bounds array access. The test for p >= 0 should come first to protect against an invalid access.
temp_upper = values[p];
temp_upper is only assigned to in the function, so this line effectively does nothing.
The algorithm looks like half of insertion sort and half of selection sort, which totals to nothing at all. ;) The process of selection sort is for each element, find the smallest or largest remaining element and swap the two. If moving from right to left, look for the largest, and if moving from left to right, look for the smallest. It looks like this for left to right:
void selectSort()
{
// For each element in the array
// Starting with the next element
// Look for a smaller value
// If the current element isn't the smallest
// Swap with the smaller value that was found
} Filling in the comments with actual code is straightforward once you understand the logic:
void selectSort()
{
// For each element in the array
for (int i = 0; i < arraysize; i++)
{
int min_index = i;
// Starting with the next element
for (int j = i + 1; j < arraysize; j++)
{
// Look for a smaller value
if (values[j] < values[min_index])
{
min_index = j;
}
}
// If the current element isn't the smallest
if (min_index != i)
{
// Swap with the smaller value that was found
swap(&values[i], &values[min_index]);
}
}
}