Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Mar 25th, 2008, 10:31 AM   #1
gmann145
Newbie
 
Join Date: Jan 2008
Posts: 7
Rep Power: 0 gmann145 is on a distinguished road
Exclamation 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



c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void selectionSort(char [], int);
  5.  
  6.  
  7. int main()
  8. {
  9. const int numNames = 20, size = 17;
  10. char names[numNames][size]={"Collins, Bill", "Smith, Bart", "Allen, Jim",
  11. "Griffin, Jim", "Stamey, Marty", "Rose, Geri",
  12. "Taylor, Terri", "Looney, Joe", "Wolfe, Bill",
  13. "James, Jean", "Weaver, Jim", "Pore, Bob",
  14. "Mann, Gregg", "Schneider, Jon", "Johnson, Jill",
  15. "Harrison, Rose", "Setzer, Cathy",
  16. "Pike, Gordon", "Holland, Beth"};
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. system("pause");
  24. return 0;
  25. }
  26.  
  27.  
  28. void selectionSort(char arrays[][SIZE], int rows)
  29. {
  30. int startScan, minIndex, index;
  31. int z;
  32. char minValue[NUM_NAMES][size];
  33.  
  34. for (startScan = 0; startScan < (rows - 1); startScan++)
  35. {
  36. z = startScan;
  37. strncpy(minValue[0], arrays[startScan], 20);
  38.  
  39. for (index = startScan + 1; index < rows; index++)
  40. {
  41. if (strcmp(arrays[index], minValue[NUM_NAMES]) < 0)
  42. {
  43. strncpy(minValue[0], arrays[index], 20);
  44. minIndex = arrays[z];
  45. }
  46. }
  47. strncpy(arrays[startScan], arrays[minIndex] , 20);
  48. }
  49. }
gmann145 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
An Attempt at a DBMS grimpirate PHP 8 Apr 17th, 2007 1:01 PM
Throwing an exception when using string constructor csrocker101 C# 3 Apr 8th, 2007 2:04 PM
Help with breaking apart a string csrocker101 C# 6 Apr 6th, 2007 7:50 AM
Function Parameters grimpirate PHP 10 Mar 14th, 2007 6:55 PM
selection sort hopeolicious C++ 2 Mar 15th, 2005 12:47 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:22 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC