//Function to swap a child node with its parent node public void NodeSwap(int childIndex, int parentIndex) { //Temp variable to hold node while we swap them HeapNode tempNode = nodeList[childIndex]; nodeList[childIndex] = nodeList[parentIndex]; nodeList[parentIndex] = tempNode; }
//Add a node to the end of the minHeap (leftmost position at the bottom of the tree), then HeapifyUp public void Enqueue(Node graphNode, int distFromStart) { HeapNode newNode = new HeapNode(graphNode, distFromStart); //Add this node to the end of the list, the leftmost position at the bottom of the tree this.NodeList.Add(newNode); this.NumberNodes++; //Ensure the smallest element is at the root this.HeapifyUp(); }
public HeapTree() { this.root = null; this.nodeList = new List <HeapNode>(); this.numberNodes = 0; }