public void MergeSort(CompareDelegate compareMethod, BackgroundWorker bgWorker) // Uses a CompareDelegate method to accomplish merge step. { int i, midPos; GArrayList <T> leftList = new GArrayList <T>(); GArrayList <T> rightList = new GArrayList <T>(); if (!bgWorker.CancellationPending) { if (this.count < 100) { this.SelectionSort(compareMethod, bgWorker); } 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, bgWorker); rightList.MergeSort(compareMethod, bgWorker); this.Merge(leftList, rightList, compareMethod); } } }
public void MergeSort() // Uses the IComparable<T> CompareTo() method to accomplish merge step. { int i, midPos; GArrayList <T> leftList = new GArrayList <T>(); GArrayList <T> rightList = new GArrayList <T>(); if (this.count < 100) { this.SelectionSort(); } 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(); rightList.MergeSort(); this.Merge(leftList, rightList); } }
public void Merge(GArrayList <T> leftList, GArrayList <T> rightList, // Uses a CompareDelegate method. CompareDelegate 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++; } } }
public void Merge(GArrayList <T> leftList, GArrayList <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++; } } }
public void Copy(GArrayList <T> sourceList) { this.Clear(); if (sourceList.count > 0) { if (sourceList[1] is ICloneable) // Perform deep copy { foreach (T data in sourceList) { this.Add((T)((ICloneable)data).Clone()); } } else if (default(T) == null) { ProcessError("Use of the GArrayList 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); } } } }
public void QuickSort(CompareDelegate compareMethod) // Uses a CompareDelegate method. { int i; T pivot; GArrayList <T> leftList = new GArrayList <T>(); GArrayList <T> rightList = new GArrayList <T>(); if (this.count < 100) { this.SelectionSort(compareMethod); } else { pivot = this[1]; for (i = 2; i <= this.count; i++) { if (this[i].CompareTo(pivot) < 0) { leftList.Add(this[i]); } else { rightList.Add(this[i]); } } leftList.Add(pivot); leftList.QuickSort(compareMethod); rightList.QuickSort(compareMethod); this.Merge(leftList, rightList); } }
public static GArrayList <T> operator+(GArrayList <T> list1, GArrayList <T> list2) { GArrayList <T> returnList = list1.Clone(); foreach (T data in list2) { returnList.Add(data); } return(returnList); }
private void IncreaseCapacity() { GArrayList <T> tempList = new GArrayList <T>(2 * this.capacity); foreach (T data in this) { tempList.Add(data); } this.capacity = tempList.capacity; this.count = tempList.count; this.items = tempList.items; }
public static GArrayList <T> operator-(GArrayList <T> list1, GArrayList <T> list2) { GArrayList <T> returnList = new GArrayList <T>(); foreach (T data in list1) { if (list2.LinearSearch(data) < 0) { returnList.Add(data); } } return(returnList); }
public static GArrayList <T> operator|(GArrayList <T> list1, GArrayList <T> list2) { int index; GArrayList <T> returnList = list1.Clone(); foreach (T data in list2) { index = list1.LinearSearch(data); if (index < 0) { returnList.InsertAt(-index, data); } } return(returnList); }
public void QuickSort() // Uses the IComparable<T> CompareTo() method. { int i; T pivot; GArrayList <T> leftList = new GArrayList <T>(); GArrayList <T> rightList = new GArrayList <T>(); if (this.count < 100) { this.SelectionSort(); } else { pivot = this[1]; for (i = 2; i <= this.count; i++) { if (this[i].CompareTo(pivot) <= 0) { leftList.Add(this[i]); } else { rightList.Add(this[i]); } } leftList.Add(pivot); leftList.QuickSort(); rightList.QuickSort(); for (i = 1; i <= leftList.count; i++) { this[i] = leftList[i]; } for (i = 1; i <= rightList.count; i++) { this[leftList.count + i] = rightList[i]; } //this.Clear(); //for (i=1; i<=leftList.count; i++) // this.Add(leftList[i]); //for (i=1; i<=rightList.count; i++) // this.Add(rightList[i]); } }
public void QuickSort(CompareDelegate compareMethod, BackgroundWorker bgWorker) // Uses a CompareDelegate method. { int i; T pivot; GArrayList <T> leftList = new GArrayList <T>(); GArrayList <T> rightList = new GArrayList <T>(); if (!bgWorker.CancellationPending) { if (this.count < 100) { this.SelectionSort(compareMethod, bgWorker); } else { pivot = this[1]; for (i = 2; i <= this.count; i++) { if (compareMethod(this[i], pivot) <= 0) { leftList.Add(this[i]); } else { rightList.Add(this[i]); } } leftList.Add(pivot); leftList.QuickSort(compareMethod, bgWorker); rightList.QuickSort(compareMethod, bgWorker); for (i = 1; i <= leftList.count; i++) { this[i] = leftList[i]; } for (i = 1; i <= rightList.count; i++) { this[leftList.count + i] = rightList[i]; } } } }
public GArrayList(GArrayList <T> sourceList) // Copy constructor { this.Copy(sourceList); }