Ejemplo n.º 1
0
        //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;
        }
Ejemplo n.º 2
0
        //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();
        }
Ejemplo n.º 3
0
 public HeapTree()
 {
     this.root        = null;
     this.nodeList    = new List <HeapNode>();
     this.numberNodes = 0;
 }