zoukankan      html  css  js  c++  java
  • 起跑爬序法的两种实现



    void BubbleSort(int *a ,int n)
    {
        
    for(int i=0;i<n-1;i++)
        {
            
    for(int j=0;j<n-1-i;j++)
            {
                
    if(a[j]>a[j+1])
                { 
    int temp=a[j];
                    a[j]
    =a[j+1];
                    a[j
    +1]=temp;
                }
            }
        }
    }
    void BubbleSort(int *a,int n)
    {
        
    for(int i=0;i<n-1;i++)
        {
            
    for(int j=n-1;j>=i+1;j--)
            {
                
    if(a[j]<a[j-1])
                {
                    
    int temp=a[j];
                    a[j]
    =a[j-1];
                    a[j
    -1]=temp;
                }

            }
        }
    }

    两者的差别在于前一种实现方案:是逐渐将大数“沉底”,而第二种实现方案,是逐渐将小数“上浮”。
    验证主函数如下
    #include<iostream>
    using namespace std;
    void main()
    {  void BubbleSort(int *A ,int n);
       int a[6]={3,7,4,5,4,9};
       BubbleSort(a,6);
       for(int k=0;k<6;k++)
       {
        cout<<a[k]<<" ";
       }
       cout<<endl;
     char f;
     cin>>f;
    }
  • 相关阅读:
    Linux三剑客grep、awk和sed
    Appium元素定位(二):UiAutomator定位
    Appium元素定位(一)
    App控件定位
    Appium 介绍及环境安装
    android Mvp简单实用
    EventBus通信
    Activity关闭另一个Acitivity
    Android输入法 监听事件
    图片形状圆角
  • 原文地址:https://www.cnblogs.com/finallyliuyu/p/1544656.html
Copyright © 2011-2022 走看看