zoukankan      html  css  js  c++  java
  • 生产1100不重复随机数并排序

    using System;
    using System.Collections;

    namespace ConsoleApplication1
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                
    int temp = 0;
                
    int[] intArr = new int[100];
                ArrayList myList 
    = new ArrayList();
                Random rnd 
    = new Random();
                
    while (myList.Count < 100)
                {
                    
    int num = rnd.Next(1101);
                    
    if (!myList.Contains(num))    // 这句是关键
                        myList.Add(num);
                }

                
    //
                
    //  转换为整形数组
                
                
    for (int i = 0; i < 100; i++)
                    intArr[i] 
    = (int)myList[i];

                
    //
                
    //  排序
                
                
    for (int i = 0; i < intArr.Length-1; i++)
                {
                    
    for (int j = 0; j < intArr.Length-1; j++)
                    {
                        
    if(intArr[j] > intArr[j+1])
                        {
                            temp 
    = intArr[j + 1];
                            intArr[j 
    + 1= intArr[j];
                            intArr[j] 
    = temp;
                        }
                    }
                }

                
    //
                
    //  输出

                
    for (int i = 0; i < intArr.Length; i++)
                {
                    Console.WriteLine(intArr[i].ToString());
                    
                }
                Console.Read();

            }
        }
    }
  • 相关阅读:
    10分钟轻松设置出 A+ 评分的 HTTP/2 网站
    GGSN与SGSN简介
    cocos游戏开发小白教程网站
    cocos2d-x JS 字符串
    cocos2d-x android工程接入第三方支付宝SDK
    pyCharm编辑器激活使用
    cocos2d-x C++ iOS工程集成第三方支付宝支付功能
    (已解决)在linux的虚拟机上安装vmware tools(实现windows与虚拟机之间的文件交互复制粘贴)
    虚拟机 liunx系统以 root 身份登录权限
    mac系统搭建SVN版本控制
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1435755.html
Copyright © 2011-2022 走看看