コード例 #1
0
ファイル: lab07.c プロジェクト: ignacioespinoso/MC202
// Torna a entrada um heap de intervalos.
Heap HeapifyInterval(Heap initial_heap) {
    // Organiza decrescentemente as prioridades máximas.
    initial_heap = HeapifyMax(initial_heap);

    // Organiza crescentemente as prioridades mínimas.
    initial_heap = HeapifyMin(initial_heap);

    return initial_heap;
}
コード例 #2
0
ファイル: heap.c プロジェクト: invisibleboy/mycompiler
/*
 * Extract the element at the top of the heap 
 */
void *
Heap_ExtractTop (Heap * root)
{
  void *heap_max;
  HeapNode *rm_node;
  int rm_pt = 0;
  int size = root->size;

  if (size < 1)
    return (NULL);
  heap_max = root->heap->element;

  rm_node = root->heap;
  while (size >= (1 << rm_pt))
    ++rm_pt;
  --rm_pt;

  while (rm_pt > 1)
    {
      if (size & (1 << --rm_pt))
	rm_node = rm_node->right;
      else
	rm_node = rm_node->left;
    }
  if (size == 1)
    {
      root->size = 0;
      L_free (heapNodePool, root->heap);
      root->heap = NULL;
      return (heap_max);
    }
  else if (size & 1)
    {
      rm_node = rm_node->right;
      rm_node->p->right = NULL;
    }
  else
    {
      rm_node = rm_node->left;
      rm_node->p->left = NULL;
    }
  root->heap->weight = rm_node->weight;
  root->heap->element = rm_node->element;
  --root->size;
  L_free (heapNodePool, rm_node);

  if (root->dir == HEAP_MAX)
    HeapifyMax (root);
  else
    HeapifyMin (root);

  return (heap_max);
}