zoukankan      html  css  js  c++  java
  • 冒泡排序大比拼看看谁的算法最简单

    一.

    ///////////////////////////////////////////////////////////////////////////////

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {

                int[] a = { 3, 4, 7, 10, 5, 9 };
                int[] b = BubbleSort(a);
                for (int i = 0; i < b.Length; i++)
                {
                    Console.Write(b[i].ToString() + " ");

                }
                Console.ReadLine();
            }

            public static int[] BubbleSort(int[] list)
            {
                int i, temp;
                for (int j = 0; j < list.Length; j++)
                {
                    for (i = list.Length - 1; i > j; i--)
                    {
                        if (list[j] < list[i])
                        {
                            temp = list[j];
                            list[j] = list[i];
                            list[i] = temp;
                        }
                    }
                }

                return list;
            }
        }
    }

    二.

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    static void Main(string[] args)
            {

               
    int[] a = { 3, 4, 7, 10, 5, 9 };
                Array.Sort(a);
               
    for (int i = 0; i < b.Length; i++)
                {
                    Console.Write(b[i].ToString()
    + " ");

                }
                Console.ReadLine();
            }


       本人博客的文章大部分来自网络转载,因为时间的关系,没有写明转载出处和作者。所以在些郑重的说明:文章只限交流,版权归作者。谢谢

  • 相关阅读:
    关于JS中判断两个数组相等
    用JS实现二叉树
    elementUI select组件 默认选择第一项
    angular [src] 绑定url或src 报XSS错误
    easy-mock本地搭建工程实操
    array splice split || string split slice 傻傻分不清楚=>终于弄清楚了
    循环=>轮回=>js循环比拼
    vue-cli 搭建工程配置 => 你想要这里都有
    git分支问题 查看、创建、关联、删除本地/远程分支
    vue知识点 && 错误点 => 持续更新
  • 原文地址:https://www.cnblogs.com/wzg0319/p/1630560.html
Copyright © 2011-2022 走看看