c#程序:将两个递增有序顺序表合并为一个递增有序顺序表 整个项目文件~多谢

2025-03-01 04:26:34
推荐回答(1个)
回答1:

又是这问题。。

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



        private string CreateOrderList(string inputStr, bool isRemoveSameItem)
        {
            //删除字符串中的空格字符
            inputStr = inputStr.Replace(" ", "");
            inputStr = inputStr.Trim();

            Hashtable hs = new Hashtable();
            List charArray = new List();
            

            foreach (char c in inputStr)
            {
                //是否移除相同项目
                if (isRemoveSameItem)
                {
                    if (!hs.ContainsKey(c))
                    {
                        hs.Add(c, c);
                        charArray.Add(c);
                    }
                }
                else
                    charArray.Add(c);
            }

            charArray.Sort();

            string s="";
            foreach(char cc in charArray)
            {
                s += cc;
            }
            return s;
        }

        private void bt_creatOrder1_Click(object sender, EventArgs e)
        {
            if (tb_order1.Text != string.Empty)
            {
                this.tb_result1.Text = CreateOrderList(tb_order1.Text, true);
                lb_msg.Text = "元素2,创建顺序表完成!";
            }
        }
        private void bt_creatOrder2_Click(object sender, EventArgs e)
        {
            if (tb_order2.Text != string.Empty)
            {
                this.tb_result2.Text = CreateOrderList(tb_order2.Text, true);
                lb_msg.Text = "元素2,创建顺序表完成!";
            }
        }

        private void bt_creatOrder12_Click(object sender, EventArgs e)
        {
            if (tb_order1.Text != string.Empty && this.tb_order2.Text != string.Empty)
            {
                this.tb_result.Text = CreateOrderList(tb_order1.Text + tb_order2.Text, true);

                lb_msg.Text = "合并顺序表操作完成!";

            }
        }
    }