示例#1
0
void heap_insert(heap* h, const unsigned int key) {
    if(heap_is_full(h)) { 
        heap_enlarge(h); 
    }
    h->nodes[h->count] = key;
	h->g->nodes[key].heap_index = h->count;
    h->count++;
    heap_heapify_up(h, h->count-1);
}
示例#2
0
void heap_insert(Heap heap, int data) {
    int i = 0;
    if (heap == NULL) {
        printf("No Heap!\n");
        return;
    }
    if (heap_is_full(heap)) {
        printf("No Space!\n");
        return;
    }

    heap->data[++heap->current_size] = data;

    /* 找到从前往后第一个比data大的结点序号 */
    for (i = heap->current_size; heap->data[i/2] > data; i /= 2) {
        heap->data[i] = heap->data[i/2];
    }
    heap->data[i] = data;
}