小编Ryu*_*Ryu的帖子

C++数组排序我

困在阵列分拣机上.必须从最大到最小的数字排序.我正在尝试两个循环(一个嵌套在另一个循环中).这是代码:

int counter=0; // inner counter
int counter2=0; // outer counter
int sparky[14]; //array set to 14 just to simplify things
int holder; // holds the highest value
int high; //stores the position where it found the value holder

while (counter2 < howmany)
 {
  holder= sparky[counter];
  while (counter <= howmany)
   {
    counter++;
    if (sparky[counter] > holder)
     {
      holder= sparky[counter];
      high= counter; 
     }
   }
   counter2++;
   counter=counter2;
   sparky[high]= sparky[counter-1];
   sparky[counter-1]=holder;
 }
Run Code Online (Sandbox Code Playgroud)

ARRAY UNSORTED:

data[ 0] = 9
data[ 1] = 8
data[ …
Run Code Online (Sandbox Code Playgroud)

c++ arrays sorting

2
推荐指数
2
解决办法
1736
查看次数

标签 统计

arrays ×1

c++ ×1

sorting ×1