Ejemplo n.º 1
0
        /*
         * 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;
        }
Ejemplo n.º 2
0
        /*
         * 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);
        }
Ejemplo n.º 3
0
 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;
         }
     }
 }
Ejemplo n.º 4
0
 /*
  * Single Value constructor
  */
 public MinHeap(HeapNode node)
 {
     m_heapArray.Add(node); // add node to heap array
     m_size = 1;            //size is 1
 }