#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*
 * Program to 
 * Terry Harvey CISC 105 section 98 TA Janet
 */

//int findMaxIndex(int input[], int size);
//void selectionSort(int input[], int size);

void selectionSort(char * input[], int size);
int findMaxIndex(char * input[], int size);

int main(){
    int i;
    char temp[30];
    char * data[5];
    printf("yo enter like five words: ");
    for (i=0; i<5; i++){
	scanf("%s", temp);
	data[i] = (char*)malloc(sizeof(char) * (1 + strlen(temp)));
	strcpy(data[i], temp);
    }

    for (i=0; i<5; i++)
	printf("%s\n", data[i]);

    selectionSort(data, 5);

    for (i=0; i<5; i++){
	printf("%s\n", data[i]);
	free(data[i]);
    }


    return 0;
}

void selectionSort(char * input[], int size){
    int maxIndex;
    char temp[30];
    if (size == 1) return;

    maxIndex = findMaxIndex(input, size);
    
    strcpy(temp, input[size-1]);
    strcpy(input[size-1], input[maxIndex]);
    strcpy(input[maxIndex], temp);

    selectionSort(input, size-1);
    return;
}

/*
 * Returns the index of the highest number
 */
int findMaxIndex(char * input[], int size){
    int maxIndex = 0;
    int i;
    for (i = 0; i < size; i++)
	if (strcmp(input[i],input[maxIndex]) > 0   )//(input[i] > input[maxIndex])
	    maxIndex = i;
    return maxIndex;
}


//void selectionSort(char * input[], int size){
//    int maxIndex;
//    char * temp;
//    if (size == 1) return;
//
//    maxIndex = findMaxIndex(input, size);
//    
//    temp = input[size-1];
//    input[size-1] = input[maxIndex];
//    input[maxIndex] = temp;
//
//    selectionSort(input, size-1);
//    return;
//}
