I want to sort this program from largest to smallest WITHOUT printing backwards, I want it to actually sort from large to small.
#include <cstdlib>
#include <iostream>
/*
Program sorts an array of integers using a selection sort.
The general algorithm repeatedly finds the smallest number
in the array and places it at the front of the list.
*/
const int size = 12;
using namespace std;
int find_small_index (int start_index, int numbers []);
void swap_values (int index1, int index2, int numbers []);
int main(int argc, char *argv[])
{
// array of numbers
int numbers [size] = {7, 9, 21, 16, 65, 8, 32, 1, 17, 41, 50, 4};
int start_index; // current starting spot for search
int small_index; // index of the smallest number in the array
int index; // index used for print the array values
start_index = 0;
// continue finding the smallest value and placing it
// at the front of the list
while (start_index < 11)
{
small_index = find_small_index (start_index, numbers);
swap_values (small_index, start_index, numbers);
start_index++;
}
In the heart of any "traditional" comparison-based sorting is comparison function. It decides whether one number should be before or after another one. You need to change it to ensure different ordering.
If you wrote this code, you should know how your selection sort chooses next element and would be able to fix your code (strictly speaking, only a single symbol needs changing)