Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: GiganticButthole on Mar 25th, 2013  |  syntax: None  |  size: 1.59 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. const int PeopleNames = 20, size = 17;
  7. void selectionSort(char[][size], int num);
  8.  
  9. int main()
  10. {
  11. char Characters[PeopleNames][size] = {"Collins, Bill", "Smith, Bart", "Allen, Jim",
  12.                                   "Griffin, Jim", "Stamey, Marty", "Rose, Geri",
  13.                                   "Taylor, Terri", "Johnson, Jill", "Allison, Jeff",
  14.                                   "Looney, Joe", "Wolfe, Bill", "James, Jean",
  15.                                   "Weaver, Jim", "Pore, Bob", "Rutherford, Greg",
  16.                                   "Javens, Renee", "Harrison, Rose", "Setzer, Cathy",
  17.                                   "Pike, Gordon", "Holland, Beth" };
  18.  
  19. selectionSort(Characters,PeopleNames);
  20. system("pause");
  21. return 0;
  22. }
  23.  
  24. void selectionSort(char Characters[][size], int num)
  25. {
  26. int startScan, minIndex;
  27. char minValue[size];
  28. for (startScan = 0; startScan < (num - 1); startScan++)
  29. {
  30.         minIndex = startScan;
  31.         for (int i=0;i<size;i++)
  32.         {
  33.                 minValue[i] = Characters[startScan][i];
  34.         }
  35.         for(int index = startScan + 1; index < num; index++)
  36.         {
  37.                 if (strcmp(Characters[index],minValue)<0)
  38.                 {
  39.                         for (int f=0;f<size;f++)
  40.                         {
  41.                                 minValue[f] = Characters[index][f];
  42.                         }
  43.                         minIndex = index;
  44.                 }
  45.         }
  46.         for (int b=0;b<size;b++)
  47.         {
  48.         Characters[minIndex][b]=Characters[startScan][b];
  49.         Characters[startScan][b] = minValue[b];
  50.         }              
  51. }
  52.         cout << "Names of people listed in alphabetical order\n";
  53.         for (int n=0;n<num;n++)
  54. {
  55.         for (int i=0;i<size;i++)
  56.         {
  57.         cout << Characters[n][i];
  58.         }
  59. cout <<endl;
  60. }