/// <summary> /// 氣泡排序 /// </summary> /// <param name="player">玩家</param> /// <returns>玩家</returns> private BrandPlayer ButtleSort(BrandPlayer player) { Brand[] a = new Brand[player.getCount()]; for (int i = 0; i < a.Length; i++) { a[i] = player.getBrand(i); } Brand temp_brand; for (int i = (player.getCount() - 1); i >= 0; i--) { for (int j = 1; j <= i; j++) { Brand first = a[j - 1]; Brand second = a[j]; if (first.getNumber() > second.getNumber()) { temp_brand = a[j - 1]; a[j - 1] = a[j]; a[j] = temp_brand; } } } player.clear(); for (int i = 0; i < a.Length; i++) { player.add(a[i]); } return(player); }
/// <summary> /// 排序牌組 /// </summary> private void sortTeam() { if (teamBrands.getCount() > 1) { // 設定最大的team號碼 int team_count = 0; for (int i = 0; i < teamBrands.getCount(); i++) { if (teamBrands.getBrand(i).Team > team_count) { team_count = teamBrands.getBrand(i).Team; } } // 設定新的陣列以最大的team號碼 BrandPlayer[] b = new BrandPlayer[team_count]; for (int i = 0; i < b.Length; i++) { b[i] = new BrandPlayer(); } // 把牌依照team號碼放入 for (int i = 0; i < teamBrands.getCount(); i++) { b[teamBrands.getBrand(i).Team - 1].add(teamBrands.getBrand(i)); } // 排序 for (int i = 0; i < b.Length; i++) { b[i] = ButtleSort(b[i]); } // 清除舊的,加入新的 teamBrands.clear(); for (int i = 0; i < b.Length; i++) { for (int j = 0; j < b[i].getCount(); j++) { teamBrands.add(b[i].getBrand(j)); } } } }
/// <summary> /// ��w�Ƨ� /// </summary> /// <param name="player">���a</param> /// <returns>���a</returns> private BrandPlayer ButtleSort(BrandPlayer player) { Brand[] a= new Brand[player.getCount()]; for (int i = 0; i < a.Length; i++ ) a[i] = player.getBrand(i); Brand temp_brand; for (int i = (player.getCount() - 1); i >= 0; i--) { for (int j = 1; j <= i; j++) { Brand first = a[j - 1]; Brand second = a[j]; if (first.getNumber() > second.getNumber()) { temp_brand = a[j - 1]; a[j - 1] = a[j]; a[j] = temp_brand; } } } player.clear(); for (int i = 0; i < a.Length; i++ ) player.add(a[i]); return player; }