不说废话直接上!本篇实现极小化堆(概念:堆顶最小,如图1)
d
函数声明HeapInit()初始化操作;HeapInsert()插入操作;DeleteMin()删除最小元素操作
#include<iostream>
using namespace std;
typedef struct minheap *Heap;
typedef struct minheap{
int last,maxsize;
int *str;
}Minheap;
Heap HeapInit (int size){
Heap h=(Heap)malloc(sizeof(Minheap));
h->maxsize=size;
h->str=(int*)malloc((h->maxsize+1)*sizeof(int));
h->last=0;
}
//插入
void HeapInsert(Heap h,int x){
if(h->last==h->maxsize)return;
int i=&