From e4629296123bf2ae6674622266b062d71e342ab7 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Wed, 20 Apr 2022 15:33:45 +0100 Subject: [PATCH] Added HeapNode --- C#/Datastructures/Heap/HeapNode.cs | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 C#/Datastructures/Heap/HeapNode.cs diff --git a/C#/Datastructures/Heap/HeapNode.cs b/C#/Datastructures/Heap/HeapNode.cs new file mode 100644 index 0000000..a96c9fd --- /dev/null +++ b/C#/Datastructures/Heap/HeapNode.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using C_.Datastructures.Generic; +using System.Threading.Tasks; + +namespace C_.Datastructures.Heap +{ + internal class HeapNode : DirectedNode> + { + internal int LeftWeight { get; set; } + internal int RightWeight { get; set; } + + //All properties inherited from base class + public static HeapNode Create(T value) + { + //Create a new node without any children + return new HeapNode + { + Value = value + }; + } + + public static HeapNode Create(T value, HeapNode? left, HeapNode? right) + { + //Create a new node with the option of having children + return new HeapNode + { + Value = value, + Left = left, + LeftWeight = (left != default) ? 1 : 0, + Right = right, + RightWeight = (right != default) ? 1 : 0 + }; + } + } +}