• 冒泡排序大比拼看看谁的算法最简单


    一.

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

    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();
            }


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

  • 相关阅读:
    Flask-SQLAlchemy
    with 与 上下文管理器
    使用@property
    C++:如何把一个int转成4个字节?
    尝试理解Flask源码 之 搞懂WSGI协议
    qt setData()和data()
    我使用过的Linux命令之sftp
    linux下如何使用sftp命令
    Linux环境下安装JDK
    CentOS 6.5 配置IP地址的三种方法
  • 原文地址:https://www.cnblogs.com/wzg0319/p/1630560.html
Copyright © 2020-2023  润新知