Added HeapNode
This commit is contained in:
		
							
								
								
									
										38
									
								
								C#/Datastructures/Heap/HeapNode.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								C#/Datastructures/Heap/HeapNode.cs
									
									
									
									
									
										Normal file
									
								
							@@ -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<T> : DirectedNode<T, HeapNode<T>>
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        internal int LeftWeight { get; set; }
 | 
				
			||||||
 | 
					        internal int RightWeight { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //All properties inherited from base class
 | 
				
			||||||
 | 
					        public static HeapNode<T> Create(T value)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            //Create a new node without any children
 | 
				
			||||||
 | 
					            return new HeapNode<T>
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                Value = value
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static HeapNode<T> Create(T value, HeapNode<T>? left, HeapNode<T>? right)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            //Create a new node with the option of having children
 | 
				
			||||||
 | 
					            return new HeapNode<T>
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                Value = value,
 | 
				
			||||||
 | 
					                Left = left,
 | 
				
			||||||
 | 
					                LeftWeight = (left != default) ? 1 : 0,
 | 
				
			||||||
 | 
					                Right = right,
 | 
				
			||||||
 | 
					                RightWeight = (right != default) ? 1 : 0
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user