public BinaryHeap(T[] nodes, BinaryHeapType type) { Type = type; Nodes = new List <T>(); foreach (T node in nodes) { this.Add(node); } }
public BinaryHeap(T[] nodes) { Type = BinaryHeapType.MIN; Nodes = new List <T>(); foreach (T node in nodes) { this.Add(node); } }
/// <summary> /// BinaryHeap constructor with initial capacity /// </summary> /// <param name="heapType">MinHeap or MaxHeap</param> /// <param name="capacity">Heap initial capacity</param> public BinaryHeap(BinaryHeapType heapType, int capacity) { if (capacity < 1) { throw new ArgumentException("Capacity must be greater than zero"); } Capacity = capacity; _heapType = heapType; _heapItems = new TObject[capacity]; }
private BinaryHeap <ValueWrapper> CreateCustomTypeBinaryHeap(BinaryHeapType heapType) { var array = CreateIntegerArray(); var binaryHeap = new BinaryHeap <ValueWrapper>(heapType, array.Length, new ValueWrapperComparer()); foreach (var number in array) { binaryHeap.Add(new ValueWrapper(number)); } return(binaryHeap); }
private BinaryHeap <int> CreateBinaryHeap(BinaryHeapType heapType) { var array = CreateIntegerArray(); var binaryHeap = new BinaryHeap <int>(heapType, array.Length); foreach (var number in array) { binaryHeap.Add(number); } return(binaryHeap); }
/// <summary> /// Create a BinaryHeap of the given type and capacity which uses the given delegate when ordering elements. /// </summary> /// <param name="ordering">Establish the heap as a minimum heap or a maximum heap.</param> /// <param name="capacity">Maximum number of items that the heap can hold.</param> /// <param name="comparisonDelegate">Used to compare items and establish their ordering. /// If null, assume the elements are IComparable and use their CompareTo method.</param> public BinaryHeap(BinaryHeapType ordering, int capacity, IComparer <TElement> comparisonDelegate = null) { Ordering = ordering; Capacity = capacity; Heap = new TElement[capacity + 1]; if (comparisonDelegate != null) { Comparer = comparisonDelegate.Compare; } else { Comparer = (e1, e2) => ((IComparable <TElement>)e1).CompareTo(e2); } Count = 0; }
/// <summary> /// BinaryHeap default constructor /// </summary> /// <param name="heapType">MinHeap or MaxHeap</param> public BinaryHeap(BinaryHeapType heapType) { Capacity = DEFAULT_SIZE; _heapType = heapType; _heapItems = new TObject[DEFAULT_SIZE]; }
public BinaryHeap(BinaryHeapType heapType, int initialCapacity) : this(heapType, initialCapacity, null) { }
public BinaryHeap(BinaryHeapType heapType, int initialCapacity, IComparer <TKey> comparer) { _heapType = heapType; _items = new List <TKey>(initialCapacity); _comparer = comparer ?? Comparer <TKey> .Default; }
/// <summary> /// PriorityQ constructor with initial capacity. /// </summary> /// <param name="heapType">MinHeap or MaxHeap</param> /// <param name="capacity">Initial capacity</param> public PriorityQ(BinaryHeapType heapType, int capacity) : base(heapType, capacity) { heapIndices = new Dictionary <TObject, int>(this.Capacity); }
public BinaryHeap(BinaryHeapType type) { Type = type; Nodes = new List <T>(); }
public BinaryHeap() { Type = BinaryHeapType.MIN; Nodes = new List <T>(); }