/// <summary> /// 按长度排序 /// </summary> public void Sort(SegList list) { int max = 0; for (int i = 0; i < list.Count - 1; ++i) { max = i; for (int j = i + 1; j < list.Count; ++j) { string str1 = list.GetElem(j).ToString(); string str2 = list.GetElem(max).ToString(); int l1; int l2; if (str1 == "null") { l1 = 0; } else { l1 = str1.Length; } if (str2 == "null") { l2 = 0; } else { l2 = str2.Length; } if (l1 > l2) { max = j; } } object o = list.GetElem(max); list.SetElem(max, list.GetElem(i)); list.SetElem(i, o); } }
/// <summary> /// 按长度排序 /// </summary> public void Sort(SegList list) { for (var i = 0; i < list.Count - 1; ++i) { var max = i; for (var j = i + 1; j < list.Count; ++j) { var str1 = list.GetElem(j).ToString(); var str2 = list.GetElem(max).ToString(); var l1 = str1 == "null" ? 0 : str1.Length; var l2 = str2 == "null" ? 0 : str2.Length; if (l1 > l2) { max = j; } } var o = list.GetElem(max); list.SetElem(max, list.GetElem(i)); list.SetElem(i, o); } }