(C#)冒泡排序 Bubble Sort

来源:互联网 发布:电脑用手机网络 编辑:程序博客网 时间:2024/06/05 11:39
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Sort{    class Bubble    {        public static void BubbleSort(List<int> list)        {            int tmp;            for (int i = 0; i < list.Count; ++i)            {                for (int j = list.Count - 1; j > i; --j)                {                    if (list[j - 1] > list[j])                    {                        tmp = list[j - 1];                        list[j - 1] = list[j];                        list[j] = tmp;                    }                }            }        }        //public static void BubbleSort(List<int> list)        //{        //    int tmp;        //    for (int i = 0; i < list.Count; ++i)        //    {        //        for (int j = 0; j < list.Count - i - 1; ++j)        //        {        //            if (list[j] > list[j + 1])        //            {        //                tmp = list[j + 1];        //                list[j + 1] = list[j];        //                list[j] = tmp;        //            }        //        }        //    }        //}    }}


 

原创粉丝点击