// Update is called once per frame void Update() { while (!done) { showCharacters(); //UI: What would you like to do? // New OR Load OR BACK? choice = choice; switch (choice) { case (CHOICE.NEW): //CreateCharacter(); break; case (CHOICE.LOAD): loadCharacters(); break; default: done = true; break; } } //Return back to before }
} // выбор алгоритма private void button1_Click(object sender, EventArgs e) { if (array_of_peak.Count > 1 && Choice != CHOICE.NUUL) { List <int> parameters = new List <int>(); Arc Line = new Arc(); int[] distance = new int[array_of_peak.Count]; List <Peak> array_of_peak1 = new List <Peak>(array_of_peak); List <Arc> array_of_arc1 = new List <Arc>(array_of_arc); distance = Line.Work(array_of_arc1, array_of_peak1, Choice, ref parameters); if (Choice != CHOICE.Analith) { textBox2.Text = "Результат работы алгоритма: " + Choice.ToString() + "\r\n"; for (int i = 1; i < array_of_peak.Count; i++) { textBox2.Text += "точка 0 - точка " + array_of_peak[i].number_peak + ": " + (distance[i] == Int32.MaxValue || distance[i] <= 0 ? "Нет пути" : distance[i].ToString()) + "\r\n"; } textBox2.Text += "Время работы алгоритма в милесекундах: " + parameters[0] + "\r\n"; textBox2.Text += "Количество сравнений: " + parameters[1] + "\r\n"; textBox2.Text += "Количество пререстановок: " + parameters[2] + "\r\n"; } else { textBox2.Text = "Результат работы алгоритмов:\r\n"; for (int i = 1; i < array_of_peak.Count; i++) { textBox2.Text += "точка 0 - точка " + array_of_peak[i].number_peak + ": " + (distance[i] == Int32.MaxValue || distance[i] <= 0 ? "Нет пути" : distance[i].ToString()) + "\r\n"; } CHOICE key = CHOICE.NUUL; for (int i = 0; i < 9; i += 3) { key++; textBox2.Text += "Алгоритм " + key.ToString() + "\r\n"; textBox2.Text += "Время работы алгоритма в миллисекундах: " + parameters[i] + "\r\n"; textBox2.Text += "Количество сравнений: " + parameters[i + 1] + "\r\n"; textBox2.Text += "Количество пререстановок: " + parameters[i + 2] + "\r\n"; } } } else { if (Choice == CHOICE.NUUL) { MessageBox.Show("Задайте алгоритм!", "FATAL ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Задайте хотя бы две вершины!", "FATAL ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } Choice = CHOICE.NUUL; radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; } // вывод информации
public int[] Work(List <Arc> arc, List <Peak> peak, CHOICE Choice, ref List <int> parameters) { Stopwatch stopForStop = new Stopwatch(); int[] distance = new int[peak.Count]; int comparisons = 0; // сравнения int permutations = 0; // перестановки switch (Choice) { case CHOICE.FloydWarshell: stopForStop.Start(); distance = FloydWarshell(arc, peak, ref comparisons, ref permutations); stopForStop.Stop(); parameters.Add((int)stopForStop.ElapsedMilliseconds); stopForStop.Reset(); break; case CHOICE.BellmanFord: stopForStop.Start(); distance = BellmanFord(arc, peak.Count, ref comparisons, ref permutations); stopForStop.Stop(); parameters.Add((int)stopForStop.ElapsedMilliseconds); stopForStop.Reset(); break; case CHOICE.Dijkstra: stopForStop.Start(); distance = Dijkstra(arc, peak, ref comparisons, ref permutations); stopForStop.Stop(); parameters.Add((int)stopForStop.ElapsedMilliseconds); stopForStop.Reset(); break; case CHOICE.Analith: parameters = Analith(ref distance, arc, peak); break; } if (Choice != CHOICE.Analith) { parameters.Add(comparisons); parameters.Add(permutations); } return(distance); } // вызов алгоритмов
static void q15() { // char choice = 'y'; // The problems with the below switch are that: // (1) There are no break statements at the end of the case statements // (2) There is no default case //switch(choice) //{ // case 'y': Console.WriteLine("The lady is for turning"); // case 'n': Console.WriteLine("They lady is not for turning"); //} CHOICE choice = CHOICE.YES; switch (choice) { case CHOICE.YES: Console.WriteLine("The lady is for turning"); break; case CHOICE.NO: Console.WriteLine("They lady is not for turning"); break; default: break; } }
} // выбор алгоритма private void radioButton4_CheckedChanged(object sender, EventArgs e) { Choice = CHOICE.Analith; } // выбор алгоритма
} // выбор алгоритма private void radioButton3_CheckedChanged(object sender, EventArgs e) { Choice = CHOICE.Dijkstra; } // выбор алгоритма
} // выбор алгоритма private void radioButton2_CheckedChanged(object sender, EventArgs e) { Choice = CHOICE.BellmanFord; } // выбор алгоритма
private void radioButton1_CheckedChanged(object sender, EventArgs e) { Choice = CHOICE.FloydWarshell; } // выбор алгоритма