示例#1
0
        public LinkList <int> Merge(LinkList <int> Ha, LinkList <int> Hb)
        {
            //将两表合并成一表的算法实现如下:
            LinkList <int> Hc = new LinkList <int>();
            Node <int>     p  = Ha.Next;
            Node <int>     q  = Hb.Next;
            Node <int>     s  = new Node <int>();

            Hc      = Ha;
            Hc.Next = null;
            while (p != null && q != null)
            {
                if (p.Data < q.Data)
                {
                    s = p;
                    p = p.Next;
                }
                else
                {
                    s = q;
                    q = q.Next;
                }
                Hc.Append(s);
            }
            if (p == null)
            {
                p = q;
            }
            while (p != null)
            {
                s = p;
                p = p.Next;
                Hc.Append(s);
            }
            return(Hc);
        }