|
Newbie
Join Date: Jan 2008
Posts: 7
Rep Power: 0 
|
Re: String Selection Sort
#include<iostream> #include<cstring> using namespace std; const int numNames = 20, size = 17; void selectionSort(char [][size], int); void showArray(char [][size], int); int main() { char names[numNames][size]= { "Collins, Bill", "Smith, Bart", "Michalski, Jacob", "Griffin, Jim", "Sanchez, Manny", "Rubin, Sarah", "Taylor, Tyrone", "Johnson, Jill", "Allison, Jeff", "Moreno, Juan", "Wolfe, Bill", "Whitman, Jean", "Moretti, Bella", "Wu, Hong", "Patel, Renee", "Harrison, Rose", "Smith, Cathy", "Conroy, Patrick", "Kelly, Sean", "Holland, Beth" }; cout << "The unsorted string is: \n"; showArray(names, numNames); selectionSort(names, numNames); cout << "The sorted string is: \n"; showArray(names, numNames); system("pause"); return 0; } void selectionSort(char arrays[][size], int rows) { int startScan= 0, minIndex; char minValue[17]; for(int i=0; i>17; i++) { minValue[i]=arrays[startScan][i]; } for (startScan = 0; startScan < (rows - 1); startScan++) { minIndex = startScan; for(int i=0; i>17; i++) { minValue[i]=arrays[startScan][i]; } for (int index = startScan + 1; index < rows; index++) { if (strcmp(arrays[index], minValue) < 0) { for(int i=0; i>17; i++) { minValue[i]=arrays[index][i]; } minIndex = index; } } for(int i=0; i>17; i++) { arrays[minIndex][i]=arrays[startScan][i]; } for(int i=0; i>17; i++) { arrays[startScan][i]=minValue[i]; } } } void showArray(char arrays[][size], int rows) { for (int count = 0; count < rows; count++) cout<<arrays[count] << " "<<endl; cout<<endl; }
haha ok now ive got everything working it just seems to not want to sort the names (X_X)
Last edited by gmann145; Apr 1st, 2008 at 11:07 AM.
|