How do you write a program using "selection sort"?



i have to write a program for class and would like to know how to write a program using selection sort to sort names in alphabetical order.
how do i make this work?


#include <iostream>

using namespace std;

void SelectionSort(int values[], int numValues) {
int endIndex = numValues ¡V 1;
for (int current=0; current<endIndex; current++)
Swap(values[current],
values[MinIndex(values, current, endIndex)]);
}
count++;
swap(arr[alphabetical], arr[index1]);

}
}

void swap(int &a, int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}

int main()
{
int a[5]={john,mary,ryan,hannah,bob};

int counta = 1;

//for an array of size 5
cout<<"This is the array unsorted: "<<endl;
for (int i = 0; i < 5; i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
selsort(a, 5, counta);
cout<<"This is the array sorted: "<<endl;
for (int i = 0; i < 5; i++)
{
cout<<a[i]<<" ";
}
cout<<endl<<"It took "<<counta<<" swaps to sort it."<<endl<<endl;


return 0;
}
Topic archived. No new replies allowed.