using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Ex08_4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void Sort(int[] list)
        {
            int i, j, temp;
            bool done = false;
            j = 1;
            while ((j < list.Length) && (!done))//判断长度
            {
                done = true;
                for (i = 0; i < list.Length - j; i++)
                {
                    if (list[i] > list[i + 1])
                    {
                        done = false;
                        temp = list[i];
                        list[i] = list[i + 1];//交换数据
                        list[i + 1] = temp;
                    }
                }
                j++;
            }
        }

        public void SelectSort(int[] list)
        {
            for (int i = 0; i < list.Length - 1; i++)
            {
                int min = i;
                for (int j = i + 1; j < list.Length; j++)
                {
                    if (list[j] < list[min])
                        min = j;
                }
                int t = list[min];
                list[min] = list[i];
                list[i] = t;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int[] myArray1 = new int[12];
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "" && textBox6.Text != "" && textBox7.Text != "" && textBox8.Text != "" && textBox9.Text != "" && textBox10.Text != "" && textBox11.Text != "" && textBox12.Text != "")
            {
                myArray1[0] = Convert.ToInt32(textBox1.Text);
                myArray1[1] = Convert.ToInt32(textBox2.Text);
                myArray1[2] = Convert.ToInt32(textBox3.Text);
                myArray1[3] = Convert.ToInt32(textBox4.Text);
                myArray1[4] = Convert.ToInt32(textBox5.Text);
                myArray1[5] = Convert.ToInt32(textBox6.Text);
                myArray1[6] = Convert.ToInt32(textBox7.Text);
                myArray1[7] = Convert.ToInt32(textBox8.Text);
                myArray1[8] = Convert.ToInt32(textBox9.Text);
                myArray1[9] = Convert.ToInt32(textBox10.Text);
                myArray1[10] = Convert.ToInt32(textBox11.Text);
                myArray1[11] = Convert.ToInt32(textBox12.Text);

                Sort(myArray1);
                label1.Text = myArray1[0].ToString();
                label2.Text = myArray1[1].ToString();
                label3.Text = myArray1[2].ToString();
                label4.Text = myArray1[3].ToString();
                label5.Text = myArray1[4].ToString();
                label6.Text = myArray1[5].ToString();
                label7.Text = myArray1[6].ToString();
                label8.Text = myArray1[7].ToString();
                label9.Text = myArray1[8].ToString();
                label10.Text = myArray1[9].ToString();
                label11.Text = myArray1[10].ToString();
                label12.Text = myArray1[11].ToString();
            }
            else
            {
                MessageBox.Show(this, "排序数据不完整，请重新输入！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int[] myArray1 = new int[12];
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "" && textBox6.Text != "" && textBox7.Text != "" && textBox8.Text != "" && textBox9.Text != "" && textBox10.Text != "" && textBox11.Text != "" && textBox12.Text != "")
            {
                myArray1[0] = Convert.ToInt32(textBox1.Text);
                myArray1[1] = Convert.ToInt32(textBox2.Text);
                myArray1[2] = Convert.ToInt32(textBox3.Text);
                myArray1[3] = Convert.ToInt32(textBox4.Text);
                myArray1[4] = Convert.ToInt32(textBox5.Text);
                myArray1[5] = Convert.ToInt32(textBox6.Text);
                myArray1[6] = Convert.ToInt32(textBox7.Text);
                myArray1[7] = Convert.ToInt32(textBox8.Text);
                myArray1[8] = Convert.ToInt32(textBox9.Text);
                myArray1[9] = Convert.ToInt32(textBox10.Text);
                myArray1[10] = Convert.ToInt32(textBox11.Text);
                myArray1[11] = Convert.ToInt32(textBox12.Text);

                SelectSort(myArray1);
                label13.Text = myArray1[0].ToString();
                label14.Text = myArray1[1].ToString();
                label15.Text = myArray1[2].ToString();
                label16.Text = myArray1[3].ToString();
                label17.Text = myArray1[4].ToString();
                label18.Text = myArray1[5].ToString();
                label19.Text = myArray1[6].ToString();
                label20.Text = myArray1[7].ToString();
                label21.Text = myArray1[8].ToString();
                label22.Text = myArray1[9].ToString();
                label23.Text = myArray1[10].ToString();
                label24.Text = myArray1[11].ToString();
            }
            else
            {
                MessageBox.Show(this, "排序数据不完整，请重新输入！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }
    }
}
