Converting an Int sorter (code provided) into a string sorter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Telvanni
    New Member
    • Sep 2006
    • 6

    Converting an Int sorter (code provided) into a string sorter

    Ok I'm having problems just figuring out how to convert this Sorter
    Code:
    void BubbleSort (int list[], int length)
    {
          int temp;
          int counter;
          int index;
     
          for (counter = 0; counter < length – 1; counter++)             	 
          {  // make one pass through the array
                                  		 
                for (index = 0; index < length – 1 – counter; index++)  
                   // compare side-by-side elements
                     if (list [index] > list [index+1])    
                     {                         		
                           temp = list [index];           	
                           list [index] = list [index+1];         	
                           list [index+1] = temp;
                      }
          } 	//  end of outer loop to make one pass through the array
    }
    into a string sorter. My main problem is that the strings are inside a structure
    Code:
    struct Census
    {
           string name;
           int cen80;
           int cen90;
    };
    So I'm kind of leary on how to sort the name variable from an array of this structure. I also Have to use this sort, it's for a homework assignment so thx for help in advance
  • dariophoenix
    New Member
    • Oct 2006
    • 34

    #2
    Just access the structs' strings and compare those:
    if (list[index].name > list[index+1].name) ...
    Last edited by dariophoenix; Oct 31 '06, 01:53 AM. Reason: More clear

    Comment

    • Telvanni
      New Member
      • Sep 2006
      • 6

      #3
      hmm that seems like it would work but I need to know how to pass the arrayed structure to the function itself

      Comment

      Working...