[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
Libcx-Heap
Here is a little example how to use libc-x heap :
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
Libcx-Heap
Here is a little example how to use libc-x heap :
\#include <libcx/heap.h>
static int cmp(void *d1,void* d2)
{
int i1= atoi(d1);
int i2= atoi(d2);
return (i1 < i2 ? -1 : (i1 > i2 ? 1 : 0));
}
int main()
{
heap_t *h;
int i;
//init a heap with a comparator function
//but no destroy function : we'll use static data
heap_init(&h,100,NULL,cmp);
heap_push(h,"1");
heap_push(h,"1");
heap_push(h,"20");
heap_push(h,"3");
heap_push(h,"3");
heap_push(h,"4");
heap_push(h,"15");
heap_push(h,"5");
heap_push(h,"6");
heap_push(h,"7");
heap_push(h,"7");
heap_push(h,"31");
//display content: remember that linear display isn't sorted
//because of array based implementation
//you could use a foreach loop instead
for(i=1;i<h->_max;i++)
{
printf("%s ",h->array_heap[i]);
}
printf("\n");
while(h->_max>1)
{
void *data;
heap_pop(h,&data);
printf("poping: %s\n",data);
}
return 0;
}
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
