发个排序题,全当娱乐
闲的无聊,发个排序题,看看大家还记得算法不?
问题:
用 "脚本 "对100万个随机整数排序(生成随机数的时间不计),然后写上你的排序时间。
------解决方案--------------------using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication8
{
public partial class Form1 : Form
{
protected List <int> L=new List <int> ();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
System.DateTime T1=System.DateTime.Now;
L.Sort();
MessageBox.Show((System.DateTime.Now - T1).ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
int max = int.MaxValue;
System.Random rnd = new Random();
for (int i = 0; i < 1000 * 1000; i++)
{
L.Add(rnd.Next(max));
}
}
}
}
---------------------------
---------------------------
00:00:00.2343735
---------------------------
OK
---------------------------