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_5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void Sort(int[] list)           
        {
            int inc;
            for (inc = 1; inc <= list.Length / 9; inc = 3 * inc + 1) ;
            for (; inc > 0; inc /= 3)
            {
                for (int i = inc + 1; i <= list.Length; i += inc)
                {
                    int t = list[i - 1];
                    int j = i;
                    while ((j > inc) && (list[j - inc - 1] > t))
                    {
                        list[j - 1] = list[j - inc - 1];
                        j -= inc;
                    }
                    list[j - 1] = t;
                }
            }
        }

        public void InsertSort(int[] list)
        {
            for (int i = 1; i < list.Length; i++)
            {
                int t = list[i];
                int j = i;
                while ((j > 0) && (list[j - 1] > t))
                {
                    list[j] = list[j - 1];
                    --j;
                }
                list[j] = t;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int[] myArray1 = new int[6];
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "" && textBox6.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);
                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();
            }
            else
            {
                MessageBox.Show(this, "排序数据不完整，请重新输入！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int[] myArray1 = new int[6];
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "" && textBox6.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);
                InsertSort(myArray1);
                label7.Text = myArray1[0].ToString();
                label8.Text = myArray1[1].ToString();
                label9.Text = myArray1[2].ToString();
                label10.Text = myArray1[3].ToString();
                label11.Text = myArray1[4].ToString();
                label12.Text = myArray1[5].ToString();
            }
            else
            {
                MessageBox.Show(this, "排序数据不完整，请重新输入！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

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