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

    代码如下:

    static void Main(string[] args)
            {
                int[] arr = new int[] { 87, 85, 89, 84, 76, 82, 90, 79, 78, 68 };//定义一个一维数组并赋值
                Console.WriteLine("初始序列:");
                foreach(int m in arr)   //循环遍历定义的一维数组,并输出其中的元素
                    Console.WriteLine(m+" ");
                Console.WriteLine();
                //定义两个int类型的变量,分别用来表示数组下标和存储新的数组元素
                int j, temp;
                for (int i = 0; i < arr.Length;i++ )//根据数组下标的值遍历数组元素
                {
                    j = i + 1;
                id:
                    if (arr[i] > arr[j])  //判断前后两个数的大小
                    {
                        temp = arr[i];  //将比较后大的元素赋值给定义的int变量
                        arr[i] = arr[j];//将后一个元素的值赋值给前一个元素
                        arr[j] = temp;  //将int变量中存储的元素赋值给后一个元素
                        goto id;        //返回标识
                    }
                    else                
                        if (j<arr.Length -1)
                        {
                            j++;
                            goto id;
                        }                
                }
                Console.WriteLine("排序后的序列:");
                foreach (int n in arr)
                {
                    Console.WriteLine(n+" ");
                    Console.ReadLine();
                }
            }

  • 相关阅读:
    【Swift】图文混排,ios开发中在textfield或textView中插入图片
    ios开发-指纹识别
    ios开发-程序压后台后,悄悄的抓取数据~~
    setNeedDisplay和setNeedsLayout
    rangeOfString用法
    NSThread的使用
    UIActivityIndicatorView的详细使用
    iOS高斯模糊处理
    HIbernate学习笔记(一) 了解hibernate并搭建环境建立第一个hello world程序
    Hibernate4搭建Log4J日志管理(附Log4j.properties配置详解)
  • 原文地址:https://www.cnblogs.com/myesn/p/5601617.html
Copyright © 2011-2022 走看看