示例#1
0
        public static void Sort <TNode>(ref BidiNodeUtility <TNode> .LinkList List)
            where TNode : class, IBidiNode <TNode>, IComparable <TNode>
        {
            TNode Swap;

            if (List.Count > 1u)
            {
                if (List.Count == 2)
                {
                    if (List.First.Data.CompareTo(List.Last.Data) > 0)
                    {
                        Swap            = List.First.Data;
                        List.First.Data = List.Last.Data;
                        List.Last.Data  = Swap;
                    }
                }
                else
                {
                    new SortComparable <TNode>
                    {
                        RealFirst = List.First,
                        RealLast  = List.Last,
                    }.Sort();
                }
            }
        }
示例#2
0
        public static void Sort <TNode, TComparer>(ref BidiNodeUtility <TNode> .LinkList List, ref TComparer Comparer)
            where TNode : class, IBidiNode <TNode> where TComparer : struct, IComparer <TNode>
        {
            TNode Swap;

            if (List.Count > 1u)
            {
                if (List.Count == 2)
                {
                    if (Comparer.Compare(List.First.Data, List.Last.Data) > 0)
                    {
                        Swap            = List.First.Data;
                        List.First.Data = List.Last.Data;
                        List.Last.Data  = Swap;
                    }
                }
                else
                {
                    new SortComparer <TNode, TComparer>
                    {
                        RealFirst = List.First,
                        RealLast  = List.Last,
                        Comparer  = Comparer,
                    }.Sort();
                }
            }
        }
示例#3
0
        public static void Sort <TNode, TNodeList>(
            ref BidiNodeUtility <TNode> .Dump Dump, ref TNodeList List)
            where TNode : class, IBidiNode <TNode>, IComparable <TNode> where TNodeList : struct, IBidiNodeList <TNode>
        {
            BidiNodeUtility <TNode> .LinkList Link;
            BidiNodeUtility <TNode> .Alloc(ref List, ref Dump, out Link);

            Sort(ref Link);
            List.First = Link.First.Data;
            List.Last  = Link.Last.Data;
            BidiNodeUtility <TNode> .FreeAssign(ref Link, ref Dump);
        }
示例#4
0
        public static void Sort <TNode>(
            IBidiNodeList <TNode> List)
            where TNode : class, IBidiNode <TNode>, IComparable <TNode>
        {
            BidiNodeUtility <TNode> .LinkList Link;
            BidiNodeUtility <TNode> .Alloc(List, out Link);

            Sort(ref Link);
            List.First = Link.First.Data;
            List.Last  = Link.Last.Data;
            BidiNodeUtility <TNode> .Assign(ref Link);
        }
示例#5
0
        public static void Sort <TNode>(
            ref BidiNodeUtility <TNode> .Dump Dump, IBidiNodeList <TNode> List, Comparison <TNode> Comparison)
            where TNode : class, IBidiNode <TNode>
        {
            BidiNodeUtility <TNode> .LinkList Link;
            BidiNodeUtility <TNode> .Alloc(List, ref Dump, out Link);

            Sort(ref Link, Comparison);
            List.First = Link.First.Data;
            List.Last  = Link.Last.Data;
            BidiNodeUtility <TNode> .FreeAssign(ref Link, ref Dump);
        }
示例#6
0
        public static void Sort <TNode, TNodeList>(
            ref TNodeList List, Comparison <TNode> Comparison)
            where TNode : class, IBidiNode <TNode> where TNodeList : struct, IBidiNodeList <TNode>
        {
            BidiNodeUtility <TNode> .LinkList Link;
            BidiNodeUtility <TNode> .Alloc(ref List, out Link);

            Sort(ref Link, Comparison);
            List.First = Link.First.Data;
            List.Last  = Link.Last.Data;
            BidiNodeUtility <TNode> .Assign(ref Link);
        }
示例#7
0
        public static void Sort <TNode, TComparer>(
            IBidiNodeList <TNode> List, ref TComparer Comparer)
            where TNode : class, IBidiNode <TNode> where TComparer : struct, IComparer <TNode>
        {
            BidiNodeUtility <TNode> .LinkList Link;
            BidiNodeUtility <TNode> .Alloc(List, out Link);

            Sort(ref Link, Comparer);
            List.First = Link.First.Data;
            List.Last  = Link.Last.Data;
            BidiNodeUtility <TNode> .Assign(ref Link);
        }
示例#8
0
 public bool EnsureSorted()
 {
     for (BidiNodeUtility <TNode> .LinkNode A = RealFirst,
          B = A.Next; B != RealFirst;
          A = B, B = B.Next)
     {
         if (Comparer.Compare(A.Data, B.Data) > 0)
         {
             return(false);
         }
     }
     return(true);
 }
示例#9
0
 private void Partition(
     BidiNodeUtility <TNode> .LinkNode First,
     BidiNodeUtility <TNode> .LinkNode Last)
 {
     for (X = Last.Data, I = First.Prev, J = First; J != Last; J = J.Next)
     {
         if ((object)J.Data == (object)X || 0 >= J.Data.CompareTo(X))
         {
             I      = I.Next;
             Swap   = J.Data;
             J.Data = I.Data;
             I.Data = Swap;
         }
     }
     I         = I.Next;
     Swap      = I.Data; I.Data = Last.Data;
     Last.Data = Swap;
 }
示例#10
0
            private void Sort(
                BidiNodeUtility <TNode> .LinkNode First,
                BidiNodeUtility <TNode> .LinkNode Last)
            {
                BidiNodeUtility <TNode> .LinkNode Split;
                if (First != Last && First != Last.Next)
                {
                    Partition(First, Last);
                    Split = I;

                    if (Split != RealFirst)
                    {
                        Sort(First, Split.Prev);
                    }

                    if (Split != RealLast)
                    {
                        Sort(Split.Next, Last);
                    }
                }
            }