1 List<string> position = new List<string>();//坐标 2 3 List<string> text = new List<string>();//text文本 4 /// <summary> 5 /// 冒泡排序 6 /// </summary> 7 /// <param name="dic">数据字典</param> 8 private void sortDic(Dictionary<string, string> dic) 9 { 10 int Flag = 1; //标志位 11 //外循环每次把参与排序的最大数排在最后 12 for (int i = 1; i < position.Count; i++) 13 { 14 if (Flag == 1) 15 { 16 string ls_value = string.Empty; // 临时变量 17 string ls_key = string.Empty; // 临时变量 18 Flag = 0; 19 //内层循环负责对比相邻的两个数,并把最大的排在后面 20 for (int j = 0; j < position.Count - i; j++) 21 { 22 //如果前 一个数大于后一个数,则交换两个数 23 if (int.Parse(position[j].Split(‘,‘)[1]) > int.Parse(position[j + 1].Split(‘,‘)[1])) 24 { 25 ls_key = text[j + 1]; 26 ls_value = position[j + 1]; 27 28 text[j + 1] = text[j]; 29 text[j] = ls_key; 30 position[j + 1] = position[j]; 31 position[j] = ls_value; 32 Flag = 1; 33 } 34 } 35 } 36 } 37 for (int i = 0; i < position.Count; i++) 38 { 39 dic.Add(text[i], position[i]); 40 } 41 }