/// <summary> /// 构造函数 /// </summary> public TwoSum_Sorted() { Console.WriteLine("请输入有序的数组:"); arr = GetArray(); Console.WriteLine("请输入目标"); tar = GetTarget(); RuntimeDetect rd = new RuntimeDetect(TwoSum); int[] result = TwoSum(); Console.WriteLine("解为[{0},{1}]", result[0], result[1]); rd = new RuntimeDetect(TwoSumB); result = TwoSumB(); Console.WriteLine("解为[{0},{1}]", result[0], result[1]); }
private int tar = 0; //目标 /// <summary> /// 构造函数,算法具体执行 /// </summary> public Two_Sum() { Console.WriteLine("请输入数组内数字,数字间以空格分隔:"); arr = GetArray(); Console.WriteLine("请输入一个数字,作为targe"); tar = GetTarget(); try { RuntimeDetect rd = new RuntimeDetect(twoSum); int[] result = twoSum(); Console.WriteLine("答案为:[" + result[0].ToString() + "," + result[1].ToString() + "]"); rd = new RuntimeDetect(hashtable); result = hashtable(); Console.WriteLine("答案为:[" + result[0].ToString() + "," + result[1].ToString() + "]"); } catch (Exception e) { Console.WriteLine(e.Message); } }