zoukankan      html  css  js  c++  java
  • 冒泡和选择排序

    一、冒泡排序
        1)复杂度 时间O(n^2) 稳定
        2)程序实现
        void Maopao(type a[],int n)
            {
                int i,j;
                type temp;
                for(i=1;i<n;j++)//排序
                {
                    for(j=0;j<10-i;j++)
                    {
                        if(a[j]>a[j+1])
                        {
                            temp = a[j];
                            a[j] = a[j+1];
                            a[j+1] = temp;
                        }
                    }
                }
                //输出
                 for(i=0;i<n;i++)
                    printf("%d ",a[i]);
                printf(" ");
            }
    二、选择排序
        1)复杂度 时间O(n^2) 稳定
        2)程序实现
            void SelectSort(type a[],int len)
            {
                type temp;
                int nIndex = 0;
                int i,j;
                for(i=0;i<len-1;i++)
                {
                    nIndex=i;
                    for(j=i+1;j<len;j++)
                    {
                        if(a[j]<a[nIndex])
                        {
                            nIndex = j;
                        }
                    }
                    if(nIndex != i)
                    {
                        temp = a[i];
                        a[i]= a[nIndex];
                        a[nIndex]=temp;
                    }
                }
            }

    The future's not set,there is no fate but what we make for ourselves.
  • 相关阅读:
    Kali视频学习21-25
    20159315《网络攻防实践》第六周学习总结
    Kali视频学习16-20
    20159315《网络攻防实践》第五周学习总结
    一个PE文件的逆向分析
    一个好玩的CTF题
    对于安卓锁屏中知识点小结
    安卓系统安全措施
    安卓防逆向、防动态分析、渗透测试及加固
    安卓组件漏洞防护注意事项
  • 原文地址:https://www.cnblogs.com/wang1994/p/9115440.html
Copyright © 2011-2022 走看看