|
Newbie
Join Date: Jan 2008
Posts: 7
Rep Power: 0 
|
String Selection Sort
hey all,, i have to use a selection sort function to search an array of strings, this is what ive got so far, im not sure where to put the selectionSort in the main and so still unsure if its correct
#include <iostream> using namespace std; void selectionSort(char [], int); int main() { const int numNames = 20, size = 17; char names[numNames][size]={"Collins, Bill", "Smith, Bart", "Allen, Jim", "Griffin, Jim", "Stamey, Marty", "Rose, Geri", "Taylor, Terri", "Looney, Joe", "Wolfe, Bill", "James, Jean", "Weaver, Jim", "Pore, Bob", "Mann, Gregg", "Schneider, Jon", "Johnson, Jill", "Harrison, Rose", "Setzer, Cathy", "Pike, Gordon", "Holland, Beth"}; system("pause"); return 0; } void selectionSort(char arrays[][SIZE], int rows) { int startScan, minIndex, index; int z; char minValue[NUM_NAMES][size]; 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); } }
|