Skip to content

Instantly share code, notes, and snippets.

@WuchiOnline
WuchiOnline / CSharpMaxHeapGeneric
Last active August 19, 2020 21:46
C# MaxHeap<T> where T: IComparable<T> Implementation
public class MaxHeap<T> where T: System.IComparable<T>
{
public List<T> heapList {get; set;}
public int Count {get => heapList.Count;}
private int GetLeftChildIndex(int elementIndex) => 2 * elementIndex + 1;
private int GetRightChildIndex(int elementIndex) => 2 * elementIndex + 2;
private int GetParentIndex(int elementIndex) => (elementIndex - 1) / 2;
@WuchiOnline
WuchiOnline / CSharpMinHeapGeneric.txt
Last active July 17, 2020 19:44
C# MinHeap<T> where T: IComparable<T> Implementation
public class MinHeap<T> where T: System.IComparable<T>
{
public List<T> heapList {get; set;}
public int Count {get => heapList.Count;}
private int GetLeftChildIndex(int elementIndex) => 2 * elementIndex + 1;
private int GetRightChildIndex(int elementIndex) => 2 * elementIndex + 2;
private int GetParentIndex(int elementIndex) => (elementIndex - 1) / 2;