コード例 #1
0
ファイル: BinaryHeap.cs プロジェクト: alicansa/BinaryHeap_cs
 public BinaryHeap(T[] nodes, BinaryHeapType type)
 {
     Type  = type;
     Nodes = new List <T>();
     foreach (T node in nodes)
     {
         this.Add(node);
     }
 }
コード例 #2
0
ファイル: BinaryHeap.cs プロジェクト: alicansa/BinaryHeap_cs
 public BinaryHeap(T[] nodes)
 {
     Type  = BinaryHeapType.MIN;
     Nodes = new List <T>();
     foreach (T node in nodes)
     {
         this.Add(node);
     }
 }
コード例 #3
0
ファイル: BinaryHeap.cs プロジェクト: chuongmep/Graphical
 /// <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);
        }
コード例 #6
0
 /// <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;
 }
コード例 #7
0
ファイル: BinaryHeap.cs プロジェクト: chuongmep/Graphical
 /// <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];
 }
コード例 #8
0
 public BinaryHeap(BinaryHeapType heapType, int initialCapacity) : this(heapType, initialCapacity, null)
 {
 }
コード例 #9
0
 public BinaryHeap(BinaryHeapType heapType, int initialCapacity, IComparer <TKey> comparer)
 {
     _heapType = heapType;
     _items    = new List <TKey>(initialCapacity);
     _comparer = comparer ?? Comparer <TKey> .Default;
 }
コード例 #10
0
ファイル: PriorityQ.cs プロジェクト: chuongmep/Graphical
 /// <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);
 }
コード例 #11
0
ファイル: BinaryHeap.cs プロジェクト: alicansa/BinaryHeap_cs
 public BinaryHeap(BinaryHeapType type)
 {
     Type  = type;
     Nodes = new List <T>();
 }
コード例 #12
0
ファイル: BinaryHeap.cs プロジェクト: alicansa/BinaryHeap_cs
 public BinaryHeap()
 {
     Type  = BinaryHeapType.MIN;
     Nodes = new List <T>();
 }