inline void TimerBase::heapDelete() { ASSERT(m_nextFireTime == 0); heapPop(); timerHeap().removeLast(); m_heapIndex = -1; }
int main(int argc, char* argv[]) { int T, N; scanf("%d", &T); for (int test_case = 1; test_case <= T; test_case++) { scanf("%d", &N); heapInit(); for (int i = 0; i < N; i++) { int value; scanf("%d", &value); heapPush(value); } printf("#%d ", test_case); for (int i = 0; i < N; i++) { int value; heapPop(&value); printf("%d ", value); } printf("\n"); } return 0; }
int main() { int i,n,x; heap *p=NULL; p=heapAlloc(); scanf("%d",&n); heapInit(p,sizeof(int),n+1,gt); for(i=0;i<n/2;i++) { x=i+n/2; heapPush(p,&x); } for(i=0;i<n/2;i++) heapPush(p,&i); while(!heapEmpty(p)) { heapPop(p,&x); printf("%d%c",x,heapEmpty(p)?'\n':' '); } return 0; }
int main() { Heap* hh = heapNew( 1 ); heapInsert( hh, "first", 1 ); long pp; char* itemout = heapPop( hh, &pp ); printf( "%s\n", itemout ); printf( "size:%d\n", hh->size ); heapInsert( hh, "one", 1 ); heapInsert( hh, "ten", 10 ); while( !heapEmpty( hh ) ) { itemout = heapPop( hh, &pp ); printf( "%s\n", itemout ); printf( "size:%d\n", hh->size ); } heapInsert( hh, "ten", 10 ); heapInsert( hh, "one", 1 ); while( !heapEmpty( hh ) ) { itemout = heapPop( hh, &pp ); printf( "%s\n", itemout ); printf( "size:%d\n", hh->size ); } heapInsert( hh, "384", 384 ); heapInsert( hh, "887", 887 ); heapInsert( hh, "778", 778 ); while( !heapEmpty( hh ) ) { itemout = heapPop( hh, &pp ); printf( "%s\n", itemout ); printf( "size:%d\n", hh->size ); } int i; for(i=0; i<1000; i++) { char* payload = (char*)malloc(200*sizeof(char)); long priority = rand()%1000+1; sprintf(payload, "%ld", priority); printf( "inserting '%s' with priority %ld\n", payload, priority ); heapInsert( hh, payload, priority ); } while( !heapEmpty( hh ) ) { itemout = heapPop( hh, &pp ); printf( "%s\n", itemout ); printf( "size:%d\n", hh->size ); free(itemout); } heapDestroy( hh ); return 1; }
inline void TimerBase::heapIncreaseKey() { ASSERT(m_nextFireTime != 0); heapPop(); heapDecreaseKey(); }