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();

            }
        }
    }
  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    开源数据库在平安的应用实践
    从Oracle到PostgreSQL:Storage Index 特性 vs BRIN 索引
    Cosmos 白皮书
    基于支付场景下的微服务改造与性能优化
    MySQL数据库备份之主从同步配置
    Maven Gradle 区别
    荐书:《PostgreSQL指南:内幕探索》| 留言送书
    SQL、NoSQL、NewSQL,论开源之路谁主沉浮
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1435755.html
Copyright © 2011-2022 走看看