///------------------------------------------------------------------------------------------------- /// <summary> Selection sort. </summary> /// /// <remarks> Jaege, 17/09/2018. </remarks> /// /// <param name="array"> The array. </param> /// <param name="dgv"> The dgv. </param> ///------------------------------------------------------------------------------------------------- public void SelectionSort(ArrayList array, DataGridView dgv) { var list = array.Cast <QuestionsArrayList>().ToList(); for (int i = 0; i < array.Count - 1; i++) { int smallest = i; for (int j = i; j < array.Count; j++) { if (string.Compare(list[j].questionOperator, list[smallest].questionOperator) < 0) { smallest = j; QuestionsArrayList temp = list[i]; list[i] = list[smallest]; list[smallest] = temp; array = new ArrayList(list); dgv.DataSource = null; dgv.DataSource = array; dgv.ClearSelection(); } } } }
///------------------------------------------------------------------------------------------------- /// <summary> Insertion sort. </summary> /// /// <remarks> Jaege, 17/09/2018. </remarks> /// /// <param name="array"> The array. </param> /// <param name="dgv"> The dgv. </param> ///------------------------------------------------------------------------------------------------- public void InsertionSort(ArrayList array, DataGridView dgv) { var list = array.Cast <QuestionsArrayList>().ToList(); for (int i = 0; i < array.Count - 1; i++) { int j = i + 1; while (j > 0) { if (string.Compare(list[j - 1].questionOperator, list[j].questionOperator) < 0) { QuestionsArrayList temp = list[j - 1]; list[j - 1] = list[j]; list[j] = temp; array = new ArrayList(list); dgv.DataSource = null; dgv.DataSource = array; dgv.ClearSelection(); } j--; } } }
///------------------------------------------------------------------------------------------------- /// <summary> Gets hash table. </summary> /// /// <remarks> Jaege, 17/09/2018. </remarks> /// /// <param name="hashTable"> The hash table. </param> /// <param name="array"> The array. </param> ///------------------------------------------------------------------------------------------------- public void GetHashTable(Hashtable hashTable, ArrayList array) { QuestionsArrayList Questions = new QuestionsArrayList(questionNo1, questionOperator, questionNo2, questionEquals, questionAnswer); var cast = array.Cast <QuestionsArrayList>().ToDictionary(item => item.questionNo1 + item.questionOperator + item.questionNo2 + item.questionEquals + item.questionAnswer); hashTable = new Hashtable(cast); }
///------------------------------------------------------------------------------------------------- /// <summary> Event handler. Called by btnSend for click events. </summary> /// /// <remarks> Jaege, 17/09/2018. </remarks> /// /// <param name="sender"> Source of the event. </param> /// <param name="e"> Event information. </param> ///------------------------------------------------------------------------------------------------- private void btnSend_Click(object sender, EventArgs e) { InstructorConnection Package = new InstructorConnection(Question.instructorFirstNumber, Question.aOperator, Question.instructorSecondNumber, Question.instructorAnswer); Package.ConnectQuestion(); List = new QuestionsArrayList(Question.instructorFirstNumber, Question.aOperator, Question.instructorSecondNumber, Question.equals, Question.instructorAnswer); List.GetArray(QuestionList); List.SetDataGrid(dataGridArray, QuestionList); List.GetHashTable(QuestionTable, QuestionList); BinaryTree.AddRecursive(Question.instructorAnswer); Root = BinaryTree.SetRoot(BinaryTree); Package.UpdateControlState(btnSend); MyLinkedList.NodeListAddatFront(new Node(Question.instructorAnswer)); }
///------------------------------------------------------------------------------------------------- /// <summary> Bubble sort. </summary> /// /// <remarks> Jaege, 17/09/2018. </remarks> /// /// <param name="array"> The array. </param> /// <param name="dgv"> The dgv. </param> ///------------------------------------------------------------------------------------------------- public void BubbleSort(ArrayList array, DataGridView dgv) { var list = array.Cast <QuestionsArrayList>().ToList(); for (int i = 0; i < array.Count - 1; i++) { for (int j = 0; j < array.Count - 1 - i; j++) { if (string.Compare(list[j].questionOperator, list[j + 1].questionOperator) > 0) { QuestionsArrayList temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; array = new ArrayList(list); dgv.DataSource = null; dgv.DataSource = array; dgv.ClearSelection(); } } } }
///------------------------------------------------------------------------------------------------- /// <summary> Gets an array. </summary> /// /// <remarks> Jaege, 17/09/2018. </remarks> /// /// <param name="array"> The array. </param> ///------------------------------------------------------------------------------------------------- public void GetArray(ArrayList array) { QuestionsArrayList Questions = new QuestionsArrayList(questionNo1, questionOperator, questionNo2, questionEquals, questionAnswer); array.Add(Questions); }