private void button2_Click(object sender, EventArgs e) { SqListClass L4 = new SqListClass(); Merge3(ref L4); textBox4.Text = L4.DispList(); }
private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e) { int k = comboBox1.SelectedIndex; //使用combobox中的索引号来判断要执行什么操作 if (k == 0) { textBox2.Enabled = false; label3.Text = "长度"; textBox3.Text = L.ListLength().ToString(); } else if (k == 1) { textBox2.Enabled = true; label3.Text = "序号"; label4.Text = "元素"; Findele(); } else if (k == 2) { textBox2.Enabled = true; label3.Text = "元素"; label4.Text = "序号"; Findnum(); } else if (k == 3) { textBox2.Enabled = true; label3.Text = "序号"; label4.Text = "元素"; Insert(); } else if (k == 4) { textBox2.Enabled = true; string text3 = textBox3.Text.ToString(); string text2 = textBox2.Text.ToString(); label3.Text = "按序号"; label4.Text = "按元素"; if (text3 != "" && text2 == "") { Deletebynum(); } else if (text3 == "" && text2 != "") { Deletebyele(text2); } } else if (k == 5) { textBox2.Enabled = true; SqListClass L1 = new SqListClass(); SqListClass L2 = new SqListClass(); Split(ref L1, ref L2); label3.Text = "奇数序号的元素"; label4.Text = "偶数序号的元素"; textBox3.Text = L1.DispList(); textBox2.Text = L2.DispList(); } }
private void Merge3(ref SqListClass L4) //三路归并 { int i = 0, j = 0, k = 0, s = 0, t; int a, b, c, mind = 0; while (i < L1.length || j < L2.length || k < L3.length) { if (i >= L1.length) { a = INF; } else { a = Convert.ToInt16(L1.data[i]); } if (j >= L2.length) { b = INF; } else { b = Convert.ToInt16(L2.data[j]); } if (k >= L3.length) { c = INF; } else { c = Convert.ToInt16(L3.data[k]); } t = mindata(a, b, c, ref mind); switch (t) { case 1: L4.data[s] = mind.ToString(); s++; i++; break; case 2: L4.data[s] = mind.ToString(); s++; j++; break; case 3: L4.data[s] = mind.ToString(); s++; k++; break; } } L4.length = s; }
private void Split(ref SqListClass L1, ref SqListClass L2) //建立奇偶顺序表表 { int i = 1, j = 1, k = 1; string x = ""; while (k <= L.ListLength()) { L.GetElem(k, ref x); L1.ListInsert(i, x); i++; k++; if (k <= L.ListLength()) { L.GetElem(k, ref x); L2.ListInsert(j, x); j++; k++; } } label2.Text = "成功产生两个顺序表"; }