Exemple #1
0
        /// <summary>
        /// input file and initiate
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect = true;//该值确定是否可以选择多个文件
            dialog.Title       = "请选择文件夹";
            dialog.Filter      = "所有文件(*.*)|*.*";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string file = dialog.FileName;
                CSVReader.readCSV(file, out dt);
                userInfos = new UserInfo[dt.Rows.Count];
                userInfos = TransStruc.trans_dt_to_userInfos(dt);
                dataGridView_dp.DataSource       = userInfos;
                dataGridView_dp.Columns[1].Width = 30;
                dataGridView_dp.Columns[2].Width = 30;
                dataGridView_dp.Columns[3].Width = 120;
                dataGridView_dp.Refresh();
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    comboBox_column.Items.Add(dt.Columns[i].ToString().Trim());
                }
                string [] alg_names = new string[] { "Insert Sort", "Bubble Sort", "Simple Select Sort", "Quick Sort", "Shell Sort", "Merge Sort", "Heap Sort" };
                foreach (var name in alg_names)
                {
                    comboBox_alg.Items.Add(name);
                }
                string[] sch_names = new string[] { "Sequential Search", "BinarySearch" };
                foreach (var name in sch_names)
                {
                    comboBox_sch_alg.Items.Add(name);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// sort
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_sort_Click(object sender, EventArgs e)
        {
            if (dt != null && userInfos != null)
            {
                switch (alg_slt)
                {
                case 0:
                    userInfos = TransStruc.InsertSort_St(userInfos, comboBox_column.SelectedIndex, seq);
                    MessageBox.Show("Successfully sorted after " + userInfos.Length + " epoch!");
                    break;

                case 1:
                    userInfos = TransStruc.BubbleSort_St(userInfos, comboBox_column.SelectedIndex, seq);
                    MessageBox.Show("Successfully sorted after " + userInfos.Length + " epoch!");
                    break;

                case 2:
                    userInfos = TransStruc.SimpleSelectSort_St(userInfos, comboBox_column.SelectedIndex, seq);
                    MessageBox.Show("Successfully sorted after " + userInfos.Length + " epoch!");
                    break;

                case 3:
                    userInfos = TransStruc.QuickSort_St(userInfos, comboBox_column.SelectedIndex, 0, userInfos.Length, seq);
                    MessageBox.Show("Successfully sorted after " + userInfos.Length + " epoch!");
                    break;

                case 4:
                    userInfos = TransStruc.ShellSort_St(userInfos, comboBox_column.SelectedIndex, seq);
                    MessageBox.Show("Successfully sorted after " + userInfos.Length + " epoch!");
                    break;

                case 5:
                    MessageBox.Show("Oops! The algorithm is still under construction!");
                    return;

                case 6:
                    MessageBox.Show("Oops! The algorithm is still under construction!");
                    return;
                }
                for (int i = 0; i < comboBox_column.Items.Count; i++)
                {
                    if (i == comboBox_column.SelectedIndex)
                    {
                        sequenced[i] = true;
                    }
                    else
                    {
                        sequenced[i] = false;
                    }
                }
            }
            dataGridView_dp.Refresh();
        }