Ok i am having alittle problem with my code, I am getting 4 errors for having these things unidetitfied but they are so I dont know what is is here is the code that I have so far. The object is to have counters that will count how many comparisions and how many swaps are being made.
#include <iostream.h>
#include <stdlib.h>
#include <cstddef>
typedef int Select;
void selectionsort(Select theArray[], int n)
{
n = 5;
for (int last = n-1; last >= 1; --last)
{
int largest = indexoflargest(theArray, last + 1);
swap(theArray[largest], theArray[last]);
}
}
int indexoflargest(const Select theArray[], int size)
{
int indexsofar = 0;
for (int currentindex = 1; currentindex < size; ++currentindex)
{
if(theArray[currentindex] > theArray[indexsofar])
indexsofar = currentindex;
}
return indexsofar;
}
void swap(Select& x, Select& y)
{
Select temp = x;
x = y;
y = temp;
}