public static void test_search_insert() { List <int> arr = new List <int>(10); arr.Add(1); arr.Add(2); arr.Add(5); arr.Add(6); arr.Add(7); arr.Add(8); arr.Add(9); string out1 = ""; for (int i = 0; i < arr.Count; i++) { out1 += " " + arr[i].ToString(); } //Debug.LogError(out1); int _index = -1; int search_insert_num = 0; //Debug.LogError("SearchInsert " + search_insert_num); _index = CQuickSort.SearchInsert <int>(arr, search_insert_num, test_compare_function); //Debug.LogError("_index " + _index); search_insert_num = 3; //Debug.LogError("SearchInsert " + search_insert_num); _index = CQuickSort.SearchInsert <int>(arr, search_insert_num, test_compare_function); //Debug.LogError("_index " + _index); search_insert_num = 10; //Debug.LogError("SearchInsert " + search_insert_num); _index = CQuickSort.SearchInsert <int>(arr, search_insert_num, test_compare_function); //Debug.LogError("_index " + _index); search_insert_num = 9; //Debug.LogError("SearchInsert " + search_insert_num); _index = CQuickSort.SearchInsert <int>(arr, search_insert_num, test_compare_function); //Debug.LogError("_index " + _index); search_insert_num = 7; //Debug.LogError("SearchInsert " + search_insert_num); _index = CQuickSort.SearchInsert <int>(arr, search_insert_num, test_compare_function); //Debug.LogError("_index " + _index); }
//add by key and value public bool Add(K _key, T _value) { int index = CQuickSort.Search <K>(mListKey, _key, CompareFunction); if (index >= 0) { throw new Exception("already have key " + _key); return(false); } index = CQuickSort.SearchInsert <K>(mListKey, _key, CompareFunction); if (index >= mListKey.Count) { mListKey.Add(_key); mListValue.Add(_value); } else { mListKey.Insert(index, _key); mListValue.Insert(index, _value); } return(true); }