public bool EnumAllAlter() { ListAlt.Clear(); for (int i = 0; i < CandidateCount; i++) { ListAlt.Add(ALPHABET[i].ToString()); } return(true); }
public bool EnumAllAlter() //Метод по перечислению всех альтернатив { string s = null; List <int> cnt_list = new List <int>(); for (int i = 0; i < CandidateCount; i++) { s += ALPHABET[0]; cnt_list.Add(0); } while (true) { if (ValidValue(s)) { string str = null; for (int i = 0; i < CandidateCount; i++) { if (i != 0) { str += " > " + s[i]; } else { str += s[i]; } } ListAlt.Add(str); } if (IncrementMethod(CandidateCount - 1)) { return(true); } bool IncrementMethod(int index) { cnt_list[index]++; if (cnt_list[index] == CandidateCount) { if (index == 0) { return(true); } if (IncrementMethod(index - 1)) { return(true); } cnt_list[index] = 0; } s = s.Remove(index, 1).Insert(index, ALPHABET[cnt_list[index]].ToString()); return(false); } } bool ValidValue(string str) { for (int i = 0; i < str.Length; i++) { for (int j = i + 1; j < str.Length; j++) { if (str[i] == str[j]) { return(false); } } } return(true); } }