美文网首页
c#冒泡排序

c#冒泡排序

作者: Class_Lee | 来源:发表于2018-01-01 14:39 被阅读0次

    using System;

    namespace Sort

    {

    class MainClass

    {

    public static void Main (string[] args)

    {

    // 冒泡排序

    int[] arr = { 2, 3, 9, 6, 4, 5, 7, 1 };

    for (int i = 0; i < arr.Length - 1; i++) {

    for (int j = 0; j < arr.Length - 1 - i; j++) {

    if (arr [j] > arr [j + 1]) {

    int temp = arr [j];

    arr [j] = arr [j + 1];

    arr [j + 1] = temp;

    }

    }

    }

    foreach (int x in arr) {

    Console.WriteLine (x);

    }

    }

    }

    }

    相关文章

      网友评论

          本文标题:c#冒泡排序

          本文链接:https://www.haomeiwen.com/subject/mojtnxtx.html