-/*#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include "main.h"*/
+/* heap.c 2007-09-05 */
+
+/* Copyright 2007 Vincent Lefort */
+
+/* This file is part of the R-package `ape'. */
+/* See the file ../COPYING for licensing issues. */
#include "me.h"
/*The usual Heapify function, tailored for our use with a heap of scores*/
/*will use array p to keep track of indexes*/
-/*after scoreHeapify is called, the subtree rooted at i
+/*after scoreHeapify is called, the subtree rooted at i
will be a heap*/
/*p goes from heap to array, q goes from array to heap*/
if ((right <= n) && (HeapArray[p[right]] < HeapArray[p[smallest]]))
smallest = right;
if (smallest != i){
- swap(p,q,i, smallest);
- /*push smallest up the heap*/
+ swap(p,q,i, smallest);
+ /*push smallest up the heap*/
i = smallest; /*check next level down*/
}
else
} while(moreswap);
}
-/*heap is of indices of elements of v,
+/*heap is of indices of elements of v,
popHeap takes the index at position i and pushes it out of the heap
(by pushing it to the bottom of the heap, where it is not noticed)*/