C++按照正态分布来排列整型数组元素

2020-01-06 15:36:27王振洲

int main() 
{ 
   int input[] = {3, 6, 1, 9, 7, 8, 2}; 
   int wc=0; 
   int nCount = sizeof(input)/sizeof(int); 
   for(wc=0; wc<nCount; wc++)// 
  { 
    cout<<input[wc] << " "; 
    //cout<<"n"<<endl; 
  } 
  cout << endl; 
 
  int output[]= {3, 6, 1, 9, 7, 8, 2}; 
  sort(input,output, nCount); 
   
  return 0; 
} 

测试结果:

当int input[] = {3, 6, 1, 9,7, 8, 2, 10};,结果如下:

3 6 1 9 7 8 2 10

1 2 3 6 7 8 9 10

1 3 7 9 10 8 6 2

当int input[] = {3, 6, 1, 9,7, 8, 2, 10};,结果如下:

3 6 1 9 7 8 2

1 2 3 6 7 8 9

2 6 8 9 7 3


注:相关教程知识阅读请移步到C++教程频道。