|
Newbie
Join Date: Jan 2008
Posts: 7
Rep Power: 0 
|
Re: String Selection Sort
#include<iostream> #include<cstring> using namespace std; void selectionSort(char [], int); void showArray(char [], int); int main() { const int numNames = 20, size = 17; 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, size); selectionSort(names, SIZE); cout << "The sorted string is: \n"; showArray(names, size); system("pause"); return 0; } selectionSort(names, size); showArray(names, size); system("pause"); return 0; } void selectionSort(char arrays[][size], int rows) { int startScan, minIndex, index; int z; char minValue[NUM_NAMES][size]; for(int i=0,; i>17; i++) { minValue[i]=arrays[0][i]; } for (startScan = 0; startScan < (rows - 1); startScan++) { z = startScan; strncpy(minValue[0], arrays[startScan], 20); for (index = startScan + 1; index < rows; index++) { if (strcmp(arrays[index], minValue[NUM_NAMES]) < 0) { strncpy(minValue[0], arrays[index], 20); minIndex = arrays[z]; } } strncpy(arrays[startScan], arrays[minIndex] , 20); } } void showArray(char arrays[], int size) { for (int count = 0; count < size; count++) cout<<arrays[count] << " "; cout<<endl; }
some work of i've added since starting, i keep getting an error that says cannot convert parameter 1 from 'char [20][17]' to 'char []'
|