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

    using System;
    
    namespace c练习五
    {
        class Program
        {
            public static void Main(string[] args)
            {
                string str=Console.ReadLine();//请用户输入一个数
                string[] strArray =str.Split(' ');//用空格分隔,得到字符串数组
                
                int[] numArray=new int[strArray.Length];//将string类型转化成int类型
                for (int i = 0; i < strArray.Length; i++) {
                    int temp=Convert.ToInt32(strArray[i]);
                    numArray[i]=temp;
                }
                //Array.Sort(numArray);//Array.Sort排序法;使用clr排序法,其实是快速排序法
                //for (int i = 0; i < numArray.Length; i++) {
                    //Console.Write(numArray[i]+"");
                //}
                for (int j = 0; j < str.Length-1; j++){//外层循环来控制子for循环执行的次数 
                    //让下面的for循环执行length-1次
                    for (int i = 0; i < numArray.Length-1; i++) {
                        //numArray[i] <numArray[i+1]作比较把最大的放在后面
                    if (numArray[i+1]<numArray[i]) {
                        int temp=numArray[i];
                        numArray[i]=numArray[i+1];
                        numArray[i+1]=temp;
                    }
                }
                }
                for (int i = 0; i < numArray.Length; i++) {
                    Console.Write(numArray[i]+"");
                }
                
                
                
                // TODO: Implement Functionality Here
                
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey(true);
            }
        }
    }

  • 相关阅读:
    子集和的另外一个问题
    LCS
    表达式求值
    Singleton in java
    自绘ListBox的两种效果
    动态创建、压缩Access数据库(*.MDB)
    C# 中用stopwatch测试代码运行时间
    MVC学习笔记之数据传递
    ATM应用实现
    html的基本语法
  • 原文地址:https://www.cnblogs.com/llhhcc/p/9794958.html
Copyright © 2011-2022 走看看