选择排序错误,在c ++中有3个并行数组

时间:2014-04-13 16:12:29

标签: c++ arrays selection-sort parallel-arrays

使用3个并行数组并使用选择排序,按降序排列英里数。它按降序排序,但例如我在输入文件中输入数据如下:

  • NC 33.9 5
  • VA 22.2 0

然后该程序将打印出VA' VA'数据两次,不显示' NC'数据。 并行数组不是我的想法也不是选择排序。它们是必需的。请帮忙

void sortEntries( string initials[], double miles[], int shelters[] )
{
   int top, bottom, i, n;;
   string tempInitials;
   double tempMiles;
   int tempShelters;

   //Selection sorting for initials[]
   n = 14;
   for( top = 0; top < MAX_ENTRIES - 1; top++ )
   {  
      tempInitials = initials[smallest];
      tempMiles = miles[smallest];
      tempShelters = shelters[smalles];
      smallest = top; 
      //Locate smallest number between 1 and MAX_ENTRIES(14)
      for ( i = top; i < MAX_ENTRIES; i++ )
      {
         if ( initials[i] < tempMiles )
         {
            tempInitials = initials[i];
            tempMiles = miles[i];
            tempShelters = shelters[i];
            smallest = i;
         }
      }
      initials[top] = initials[smallest];
      miles[top] = miles[smallest];
      shelters[top] = shelters[smallest];
      initials[smallest] = tempInitials;
      miles[smallest] = tempMiles;
      shelters[smallest] = tempShelters;    
   }     

0 个答案:

没有答案