Ejemplo n.º 1
0
 public void Copy(LibGList <T> sourceList)
 {
     this.Clear();
     if (sourceList.count > 0)
     {
         if (sourceList[1] is ICloneable <T> ) // Perform deep copy
         {
             foreach (ICloneable <T> data in sourceList)
             {
                 this.Add(data.Clone());
             }
         }
         else if (sourceList[1] is ICloneable) // Perform deep copy
         {
             foreach (ICloneable data in sourceList)
             {
                 this.Add((T)data.Clone());
             }
         }
         else if (default(T) == null)
         {
             ProcessError("Use of the LibGList Copy method on a list of a reference type requires\n" +
                          "that the type implement the ICloneable interface.");
         }
         else // Perform shallow copy
         {
             foreach (T data in sourceList)
             {
                 this.Add(data);
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void MergeSort(Comparison <T> compareMethod) // Uses a Comparison<T> method to accomplish merge step.
        {
            int          i, midPos;
            LibGList <T> leftList  = new LibGList <T>();
            LibGList <T> rightList = new LibGList <T>();

            if (this.count < 100)
            {
                this.SelectionSort(compareMethod);
            }
            else
            {
                midPos = (1 + this.count) / 2;
                for (i = 1; i <= midPos; i++)
                {
                    leftList.Add(this[i]);
                }
                for (i = midPos + 1; i <= this.count; i++)
                {
                    rightList.Add(this[i]);
                }
                leftList.MergeSort(compareMethod);
                rightList.MergeSort(compareMethod);
                this.Merge(leftList, rightList, compareMethod);
            }
        }
Ejemplo n.º 3
0
        public void Merge(LibGList <T> leftList, LibGList <T> rightList, // Uses a Comparison<T> method.
                          Comparison <T> compareMethod)
        {
            int i, j, k, count = leftList.Count + rightList.Count;

            for (i = 1, j = 1, k = 1; i <= this.count; i++)
            {
                if (j <= leftList.count && k <= rightList.Count)
                {
                    if (compareMethod(leftList[j], rightList[k]) <= 0)
                    {
                        this[i] = leftList[j];
                        j++;
                    }
                    else
                    {
                        this[i] = rightList[k];
                        k++;
                    }
                }
                else if (j <= leftList.count)
                {
                    this[i] = leftList[j];
                    j++;
                }
                else
                {
                    this[i] = rightList[k];
                    k++;
                }
            }
        }
Ejemplo n.º 4
0
        public void Merge(LibGList <T> leftList, LibGList <T> rightList) // Uses the IComparable<T> CompareTo() method.
        {
            int i, j, k;

            for (i = 1, j = 1, k = 1; i <= this.count; i++)
            {
                if (j <= leftList.count && k <= rightList.count)
                {
                    if (leftList[j].CompareTo(rightList[k]) <= 0)
                    {
                        this[i] = leftList[j];
                        j++;
                    }
                    else
                    {
                        this[i] = rightList[k];
                        k++;
                    }
                }
                else if (j <= leftList.count)
                {
                    this[i] = leftList[j];
                    j++;
                }
                else
                {
                    this[i] = rightList[k];
                    k++;
                }
            }
        }
Ejemplo n.º 5
0
        private void IncreaseCapacity()
        {
            LibGList <T> tempList = new LibGList <T>(2 * this.capacity);

            foreach (T data in this)
            {
                tempList.Add(data);
            }
            this.capacity = tempList.capacity;
            this.count    = tempList.count;
            this.items    = tempList.items;
        }
Ejemplo n.º 6
0
 public LibGList(LibGList <T> sourceList) // Copy constructor
 {
     this.Copy(sourceList);
 }