- #1
heavyc
- 16
- 0
Okay here's the deal I am writing a program so that i could put a counter into a selection sort and count the comparsions and the swaps but when i wrote thw code I get 4 error messages and I don't know why so here is the code if anyone can help it would be nice thank you
Code:
#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;
}