Пример #1
0
        private void Merge2(ref SqListClass L3)//二路归并
        {
            int i = 0, j = 0, k = 0;

            while (i < L1.length && j < L2.length)
            {
                if (Convert.ToInt16(L1.data[i]) < Convert.ToInt16(L2.data[j]))
                {
                    L3.data[k] = L1.data[i];
                    i++; k++;
                }
                else
                {
                    L3.data[k] = L2.data[j];
                    j++; k++;
                }
            }
            while (i < L1.length)
            {
                L3.data[k] = L1.data[i];
                i++; k++;
            }
            while (j < L2.length)
            {
                L3.data[k] = L2.data[j];
                j++; k++;
            }
            L3.length = k;
        }
Пример #2
0
        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;
        }
Пример #3
0
        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++;
                }
            }
            MessageBox.Show("操作提示:成功产生两个顺序表");
        }