I used the "long" form of all math statements, avoided the use of pointers, and used only while loops for aesthetic purposes (simply put, I think the code is prettier when it is written like that.) I am mainly concerned about the CPU efficiency of the code.
Bubble Sort - The quintessential example of an "inefficient" sorting algorithm. Often the first sorting algorithm introduced to college students.
void BubbleSort(int Array[], int Length)
{
int CurrentIndex[2];
int TemporaryValue;
int WasThereASwap;
WasThereASwap = 1;
while (WasThereASwap == 1)
{
WasThereASwap = 0;
CurrentIndex[0] = 0;
CurrentIndex[1] = 1;
while (CurrentIndex[1] != Length)
{
if (Array[CurrentIndex[0]] > Array[CurrentIndex[1]])
{
WasThereASwap = 1;
TemporaryValue = Array[CurrentIndex[0]];
Array[CurrentIndex[0]] = Array[CurrentIndex[1]];
Array[CurrentIndex[1]] = TemporaryValue;
}
CurrentIndex[0] = CurrentIndex[0] + 1;
CurrentIndex[1] = CurrentIndex[1] + 1;
}
}
}
Selection Sort - Usually outperforms bubble sort, but it is still not a very good sorting algorithm for large arrays.
void SelectionSort(int Array[], int Length)
{
int BeginComparisonsIndex;
int CurrentComparisonIndex;
int CurrentLowestIndex;
int TemporaryValue;
BeginComparisonsIndex = 0;
while(BeginComparisonsIndex != Length)
{
CurrentComparisonIndex = BeginComparisonsIndex;
CurrentLowestIndex = BeginComparisonsIndex;
while (CurrentComparisonIndex != Length)
{
if (Array[CurrentComparisonIndex] < Array[CurrentLowestIndex])
{
CurrentLowestIndex = CurrentComparisonIndex;
}
CurrentComparisonIndex = CurrentComparisonIndex + 1;
}
TemporaryValue = Array[BeginComparisonsIndex];
Array[BeginComparisonsIndex] = Array[CurrentLowestIndex];
Array[CurrentLowestIndex] = TemporaryValue;
BeginComparisonsIndex = BeginComparisonsIndex + 1;
}
}
a[x]is*(a+x), so I'd say you've confined your use of pointers to a specific syntax. \$\endgroup\$