借wangjianjun02 (啊龙)的帖子
http://community.csdn.net/Expert/TopicView3.asp?id=5470821有两个数组:int[] a = new int[]{1,2,3,4,5,6,7,8,9,10};
int[] b = new int[]{1,2,3,4,5,6,7,8};有什么方法快速的找出这两个数组中不同的数字?大家都动手写下 最后评测下谁的速度最快
http://community.csdn.net/Expert/TopicView3.asp?id=5470821有两个数组:int[] a = new int[]{1,2,3,4,5,6,7,8,9,10};
int[] b = new int[]{1,2,3,4,5,6,7,8};有什么方法快速的找出这两个数组中不同的数字?大家都动手写下 最后评测下谁的速度最快
解决方案 »
- TrackBar调节系统声音大小
- 问下有关新浪Oauth操作的问题。
- win7下运行vs2008出现加载属性“RootNamespace”失败。
- 关于图象填充的问题
- dropdownlist在datagrid里修改时我没法绑定数据了?
- 怎么样从DATASET里的DATATABLE里过滤出一个类似SQL DISTINCT功能的记录??
- 在Web里如何共用不同虚拟目录的Session值
- access连接字符串应该怎么写,打包后才不会抱错呢
- 请问如何判断textbox输入的是数值??????
- C# 结构体转字节数组时若结构体某个变量为汉字应该怎么转换
- VS.NET 中怎么把图片转换成图标?
- 请教Windows程序连接远程access数据库建立连接问题。
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] b = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Stopwatch sw = new Stopwatch();
sw.Start(); //***********
//算法开始
//*********** //快排
Array.Sort(a);
Array.Sort(b); List<int> list = new List<int>(); int a_len = a.Length;
int b_len = b.Length;
for (int i = 0,j=0; i < a_len || j < b_len ; )
{
if (a[i] == b[j])
{
i++;
j++;
}
else if (a[i] < b[j])
{
list.Add(a[i]);
i++;
}
else
{
list.Add(b[j]);
j++;
} //判断一组扫完的情况 即==的情况
if (i >= a.Length)
{
for (; j < b.Length; j++)
{
list.Add(b[j]);
}
}
if (j >= b.Length)
{
for (; i < a.Length; i++)
{
list.Add(a[i]);
}
}
} //******************
//算法结束
//******************
sw.Stop();
Console.WriteLine(sw.Elapsed.Ticks);
for (int i = 0; i < list.Count; i++)
Console.Write("{0} ", list[i]);
Console.Read();
}
}
}
结果 (Release模式)
231 (时间)
9 10