Selection Sort

Hello I am running into a few problems in generating a Selection sort. Here is what I have so far.


javascript:tx('code')
#include <iostream>


using namespace std;

int main() { const int SIZE = 27;
int end = 26;
int values[SIZE] = {12,94,56,23,41,34,27,31,24,86,54,67,34,59,11,9,77,22,91,64,21,85,71,60,30,44,18};
cout << "Initial Values:\n";
for(int i = 0; i < SIZE; i++) {
cout << values[i] << " ";
}
cout << endl;

while(end > 0)
javascript:tx('code')

after this step I know I need to find the largest value between 0 and end.. and am trying to find the location of the largest value because i plan on swapping values. I am looking for n and n list items but am having troubles laying out the the proper selection sort. c++


Last edited on
Pseudo-code for finding max of an array:
index_of_max = 0   //assume that the first element is the greatest
for index = 1 to ...   //a loop through all other indices
   if array_value[index_of_max] < array_value[index] then
      index_of_max = index


Selection sort means doing that to increasingly shorter prefix arrays and swapping index_of_max with end.

By the way, the tags are [code][/code]
Last edited on
my error on the tags, appreciate the response! I am fairly new to this and could really use a good example of this same type of problem as a guide. I am just touching on basics but feel this is the next step in learning. Again thank you for your time and hope to hear back from you
If you want code, see the example in http://en.wikipedia.org/wiki/Selection_sort
Topic archived. No new replies allowed.