1. 程式人生 > >冒泡演算法!!

冒泡演算法!!

 int[] a=new int[10];

        private void button2_Click(object sender, EventArgs e)
        {
            a[0]=12;
            a[1]=23;
            a[2]=56;
            a[3]=89;
            a[4]=33;
            a[5]=66;
            a[6]=7;
             a[7]=15;
             a[8]=26;
             a[9]=341;
            string text = "";
            for (int i = 0; i < a.Length; i++)
            {
                for (int j = 0; j < a.Length-i-1; j++)
                {
                    if (a[j]<a[j+1])
                    {
                        int Temp = a[j + 1];
                        a[j + 1] = a[j];
                        a[j] = Temp;
                    }
                }
            }
            for (int i = 0; i < a.Length; i++)
            {
                text = text + a[i].ToString()+",";
            }
            this.textBox2.Text = text;