Class Heap<T>
A binary heap written by Sebastian Lague. Heap video
Namespace: Global
Assembly: cs.temp.dll.dll
Syntax
public class Heap<T>
where T : IHeapItem<T>
Type Parameters
Name | Description |
---|---|
T | The type of object to be sorted in the heap. |
Constructors
Heap(Int32)
Constructor taking in the max size of the heap.
Declaration
public Heap(int maxHeapSize)
Parameters
Type | Name | Description |
---|---|---|
Int32 | maxHeapSize | The maxiumum possible size of the heap. |
Properties
Count
Gets the number of items in the heap.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Add(T)
Adds a new item to the heap and sorts it.
Declaration
public void Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to be added to the heap. |
Contains(T)
Checks if the given item is in the heap.
Declaration
public bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to find. |
Returns
Type | Description |
---|---|
Boolean | True if the item is in the heap, false if it is not. |
getItem(Int32)
Retrieve an item from the heap at the given index.
Declaration
public T getItem(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index position of the item to retrieve. |
Returns
Type | Description |
---|---|
T |
RemoveFirst()
Removes the first item from the heap and sorts the heap.
Declaration
public T RemoveFirst()
Returns
Type | Description |
---|---|
T | The first item in the heap. |
UpdateItem(T)
Updates the heap position of the item given.
Declaration
public void UpdateItem(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to update the position for. |