冒泡排序

 #include<iostream>
using namespace std;
#define max 9
int main()
{
    int Array[max];
    /*for ( int i = 0;i < max;i ++)
    {
         Array[i] = max - i;
         }*/
         cout <<"原始数据:"; 
      for ( int i = 0;i < max;i ++)
      {
          cin >> Array[i];  
          }
          cout << endl;
          //开始冒泡 
          for (  int i = max-1;i > 0;i--)
          {
              for ( int j = 0;j < i;j ++)
              {
                  int temp;
                  if ( Array[j] > Array[j+1])
                  {
                       temp = Array[j];
                       Array[j] = Array[j+1];
                       Array[j+1] =  temp;
                       }
                  }
              }
              cout <<"排序后数据:\n";
                for ( int i = 0;i < max;i ++)
      {
          cout << Array[i]<<"\n";
          }
                
    system("pause");
    } 


 

你可能感兴趣的:(System)