View Single Post
Old Apr 1st, 2008, 9:45 AM   #5
gmann145
Newbie
 
Join Date: Jan 2008
Posts: 7
Rep Power: 0 gmann145 is on a distinguished road
Exclamation Re: String Selection Sort

c++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4.  
  5.  
  6. void selectionSort(char [], int);
  7. void showArray(char [], int);
  8.  
  9.  
  10. int main()
  11. {
  12. const int numNames = 20, size = 17;
  13. char names[numNames][size]= { "Collins, Bill", "Smith, Bart", "Michalski, Jacob",
  14. "Griffin, Jim", "Sanchez, Manny", "Rubin, Sarah",
  15. "Taylor, Tyrone", "Johnson, Jill", "Allison, Jeff",
  16. "Moreno, Juan", "Wolfe, Bill", "Whitman, Jean",
  17. "Moretti, Bella", "Wu, Hong", "Patel, Renee",
  18. "Harrison, Rose", "Smith, Cathy", "Conroy, Patrick",
  19. "Kelly, Sean", "Holland, Beth" };
  20.  
  21. cout << "The unsorted string is: \n";
  22. showArray(names, size);
  23. selectionSort(names, SIZE);
  24. cout << "The sorted string is: \n";
  25. showArray(names, size);
  26.  
  27. system("pause");
  28. return 0;
  29. }
  30.  
  31.  
  32. selectionSort(names, size);
  33.  
  34. showArray(names, size);
  35. system("pause");
  36. return 0;
  37. }
  38.  
  39.  
  40. void selectionSort(char arrays[][size], int rows)
  41. {
  42. int startScan, minIndex, index;
  43. int z;
  44. char minValue[NUM_NAMES][size];
  45. for(int i=0,; i>17; i++)
  46. {
  47. minValue[i]=arrays[0][i];
  48.  
  49. }
  50.  
  51. for (startScan = 0; startScan < (rows - 1); startScan++)
  52. {
  53. z = startScan;
  54. strncpy(minValue[0], arrays[startScan], 20);
  55.  
  56. for (index = startScan + 1; index < rows; index++)
  57. {
  58. if (strcmp(arrays[index], minValue[NUM_NAMES]) < 0)
  59. {
  60. strncpy(minValue[0], arrays[index], 20);
  61. minIndex = arrays[z];
  62. }
  63. }
  64. strncpy(arrays[startScan], arrays[minIndex] , 20);
  65. }
  66. }
  67.  
  68.  
  69. void showArray(char arrays[], int size)
  70. {
  71. for (int count = 0; count < size; count++)
  72. cout<<arrays[count] << " ";
  73. cout<<endl;
  74. }




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 []'
gmann145 is offline   Reply With Quote