/* * Swap Nodes of heap array */ private void SwapNode(int parent, int child) { HeapNode temp = m_heapArray[parent]; m_heapArray[parent] = m_heapArray[child]; m_heapArray[child] = temp; }
/* * Pop the root of the heap and then idle for the amount of time the process node specifies * Returns the message to print to stdout */ private String Consume() { String message; // output message HeapNode node = m_heap.RemoveMin(); // pop root Thread.Sleep(node.GetTimems()); // sleep for process nodes time to simulate running a program // output message for process that was consumed message = "Process: " + node.GetId() + " with priority: " + node.GetPriority() + " at " + DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; m_count += 1; // increase count of number of consumptions return(message); }
public void InsertNode(HeapNode node) { if (m_size == 0) { m_heapArray.Add(node); m_size += 1; } else { m_heapArray.Add(node); m_size += 1; Boolean swapped = true; int index = m_size - 1; while (swapped) { swapped = FloatUp(index); index = index / 2; } } }
/* * Single Value constructor */ public MinHeap(HeapNode node) { m_heapArray.Add(node); // add node to heap array m_size = 1; //size is 1 }