zoukankan      html  css  js  c++  java
  • C#冒泡排序算法

    用了两种形式的数据,一个是泛型List,一个是数据int[]。记录一下,作为自己学习过程中的笔记。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 冒泡排序算法
    {
        class Program
        {
            static void Main(string[] args)
            {
                List<int> _list = new List<int>() { 29, 20, 49, 84, 3, 48, 86, 95, 69, 28 };
                Bubble(_list);
                foreach (var item in _list)
                {
                    Console.WriteLine(item);
                }
                int[] bortargs = { 29, 20, 49, 84, 3, 48, 86, 95, 69, 28 };
                Bubble(bortargs);
                foreach (var article in bortargs)
                {
                    Console.WriteLine(article);
                }
                Console.ReadKey();
            }
            static void Bubble(List<int> list)
            {
                int temp = 0;
                for (int i = list.Count; i > 0; i--)
                {
                    for (int j = 0; j < i - 1; j++)
                    {
                        if (list[j] > list[j + 1])
                        {
                            temp = list[j];
                            list[j] = list[j + 1];
                            list[j + 1] = temp;
                        }
                    }
                }
            }
    
            static void Bubble(int[] args)
            {
                int temp = 0;
                for (int i = args.Length; i > 0; i--)
                {
                    for (int j = 0; j < i - 1; j++)
                    {
                        if (args[j] > args[j + 1])
                        {
                            temp = args[j];
                            args[j] = args[j + 1];
                            args[j + 1] = temp;
                        }
                    }
                }
            }
    
        }
    }
    View Code
  • 相关阅读:
    Cinema in Akiba(线段树)
    SGU
    632-掷骰子
    ZOJ
    nyoj 1129 Salvation(搜索)
    symbol table meaning
    C/C++编译和链接过程详解 (重定向表,导出符号表,未解决符号表)
    编译链接 C++
    while(cin.eof)出错 poj
    华为oj 购物单
  • 原文地址:https://www.cnblogs.com/zuimeideshi520/p/6025402.html
Copyright © 2011-2022 走看看