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

    以前在学习数据结构时,里面有很多排序方法其中就有冒泡排序。当时看着挺难得 这个和那个交换的。现在重新审视一下发现原来如此的简单⊙﹏⊙b汗 哎 真不知道当时的自己是怎么学的!o(╯□╰)o 

    1 static void Main(string[] args)
    2 {
    3 int[] a ={ 2, 43, 45, 23, 12, 34, 56, 87, 45 };
    4 int max = 0;
    5 for (int i = 0; i < a.Length; i++)
    6 {
    7 for (int j = 0; j < a.Length - 1; j++)
    8 {
    9 if (a[i] < a[j])//这是从小到大,如果是从大到小 a[i] > a[j] 即可
    10 {
    11 max = a[i];
    12 a[i] = a[j];
    13 a[j] = max;
    14 }
    15 }
    16 }
    17 //打印排序后的数组
    18 for (int i = 0; i < a.Length; i++)
    19 {
    20 Console.WriteLine(a[i]);
    21 }
    22 Console.ReadKey();
    23 }
    24 }
    复制代码
     1         static void Main(string[] args)
    2 {
    3 int[] a ={ 2, 43, 45, 23, 12, 34, 56, 87, 45 };
    4 int max = 0;
    5 for (int i = 0; i < a.Length; i++)
    6 {
    7 for (int j = 0; j < a.Length - 1; j++)
    8 {
    9 if (a[i] < a[j])//这是从小到大,如果是从大到小 a[i] > a[j] 即可
    10 {
    11 max = a[i];
    12 a[i] = a[j];
    13 a[j] = max;
    14 }
    15 }
    16 }
    17 //打印排序后的数组
    18 for (int i = 0; i < a.Length; i++)
    19 {
    20 Console.WriteLine(a[i]);
    21 }
    22 Console.ReadKey();
    23 }
    24 }
    复制代码
  • 相关阅读:
    UIView添加手势
    UIView常见属性设置汇总
    关于页面传值
    有关segue的简介
    alloc
    如何定义静态方法
    一座小城
    清明
    开通博客
    iOS学习之界面间传值
  • 原文地址:https://www.cnblogs.com/ysz12300/p/5494777.html
Copyright © 2011-2022 走看看