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

            }
        }
    }
  • 相关阅读:
    多线程编程(2):线程的同步
    C#中listview实现排序
    [PLC]S7-300的数据类型
    C# 多线程编程(4):多线程与UI操作
    Thunderbird 80 column FIX 发出的邮件也需要在80列处line break
    vsftp 500 OOPS: vsftpd: refusing to run with writable anonymous root
    科普 What is YUV
    转载:网站真的可以无密码登录么?
    Ubuntu 12.04安装Microsoft lifecam studio摄像头
    Thunderbird on Ubuntu 12.04 调整邮件列表行间距
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1435755.html
Copyright © 2011-2022 走看看