#include #include using namespace std; const int MAX_WORDS = 10000; const int MAX_WORD_LENGTH = 25; void selectionSort(char words[][MAX_WORD_LENGTH], int n); int main (int argc, char *argv[]) { char current; int i = 0, j = 0, k = 0; bool twolines = 0; char words[MAX_WORDS][MAX_WORD_LENGTH]; char temp[MAX_WORD_LENGTH]; ifstream in_stream; in_stream.open(argv[1]); while(!in_stream.eof()) { in_stream.get(current); current = tolower(current); if((current == ' ' || current == '\n') && twolines == 1) { i++; j = 0; twolines = 0; } if(j == 0 && ((current >= 'a' && current <= 'z') || (current >= '0' && current <= '9')) || j != 0) { words[i][j] = current; j++; twolines = 1; } } selectionSort(words, i ); for(int x = 0; x < i; x++) { for (int y = 0; y < MAX_WORD_LENGTH; y++) { cout << words[x][y]; } cout << endl; } return 0; } void selectionSort(char list[][MAX_WORD_LENGTH], int n) { for(int i = 0; i < n - 1; i++) { int smallest = i; for(int j = i+1;j < n; j++) { if(strcmp(list[j],list[smallest]) < 0) { smallest = j; } } char temp[1][MAX_WORD_LENGTH]; strncpy(temp[0],list[i],MAX_WORD_LENGTH); strncpy(list[i],list[smallest],MAX_WORD_LENGTH); strncpy(list[smallest],temp[0],MAX_WORD_LENGTH); } return; }