#include #include const int MAX_LENGTH = 35; typedef char string[MAX_LENGTH]; int swapCount = 0; string lines[10]; void Swap(string& X, string& Y) { string temp; strcpy(temp, X); strcpy(X, Y); strcpy(Y, temp); swapCount++; } int IndexOfLargest(const string A[], int Size) { int IndexSoFar = 0; for ( int CurrentIndex=1; CurrentIndex 0 ) IndexSoFar = CurrentIndex; } return IndexSoFar; } void SelectionSort(string A[], int N) { for ( int Last=N-1; Last >=1; --Last) { int L = IndexOfLargest(A, Last+1); Swap(A[L], A[Last]); } } void main() { int index = 0; int line = 0; ifstream InFile("otherSorts.txt"); while ( InFile.peek() != EOF ) { InFile.getline(lines[line++], MAX_LENGTH); } InFile.close(); SelectionSort(lines, line++); ofstream OutFile("5.txt"); for (int i=0; i<10; i++) { OutFile << lines[i] << "\n"; } OutFile << "\nSwap Count = " << swapCount; OutFile.close(); }