Beispiel #1
0
        //从表中删除相同数据元素
        public SeqList <int> Purge(SeqList <int> La)
        {
            SeqList <int> Lb = new SeqList <int>(La.Maxsize);

            Lb.Append(La[0]);

            for (int i = 1; i <= La.GetLength() - 1; ++i)
            {
                int j = 0;

                for (j = 0; j <= Lb.GetLength() - 1; ++j)
                {
                    if (La[i].CompareTo(Lb[j]) == 0)
                    {
                        break;
                    }
                }

                if (j > Lb.GetLength() - 1)
                {
                    Lb.Append(La[i]);
                }
            }
            return(Lb);
        }
Beispiel #2
0
        // 按升序合并两个表
        public SeqList <int> Merge(SeqList <int> La, SeqList <int> Lb)
        {
            SeqList <int> Lc = new SeqList <int>(La.Maxsize + Lb.Maxsize);
            int           i  = 0;
            int           j  = 0;
            int           k  = 0;

            //两个表中都有数据元素
            while ((i <= (La.GetLength() - 1)) && (j <= (Lb.GetLength() - 1)))
            {
                if (La[i] < Lb[j])
                {
                    Lc.Append(La[i++]);
                }
                else
                {
                    Lc.Append(Lb[j++]);
                }
            }
            //a表中还有数据元素
            while (i <= (La.GetLength() - 1))
            {
                Lc.Append(La[i++]);
            }
            //b表中还有数据元素
            while (j <= (Lb.GetLength() - 1))
            {
                Lc.Append(Lb[j++]);
            }
            return(Lc);
        }