X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fdoc%2Fheap.txt;h=df4f7534b8db5a719c727e44baaf6e1ed14dd377;hb=a6368763d08042207963c941b1c52b5fafcb0cb3;hp=64729a17fcf878bd7f30abd1c93a932480914027;hpb=0b3fa7642199922ce6c35ab9d09adcda51913f24;p=libucw.git diff --git a/ucw/doc/heap.txt b/ucw/doc/heap.txt index 64729a17..df4f7534 100644 --- a/ucw/doc/heap.txt +++ b/ucw/doc/heap.txt @@ -11,7 +11,7 @@ Binary heaps Example ------- - static uns n; + static uint n; static int heap[4]; // Create an empty heap @@ -19,22 +19,18 @@ Example #define MY_CMP(x, y) ((x) < (y)) // Insert 20, 10, 30 - heap[n + 1] = 20; - HEAP_INSERT(int, heap, n, MY_CMP, HEAP_SWAP); - heap[n + 1] = 10; - HEAP_INSERT(int, heap, n, MY_CMP, HEAP_SWAP); - heap[n + 1] = 30; - HEAP_INSERT(int, heap, n, MY_CMP, HEAP_SWAP); + HEAP_INSERT(int, heap, n, MY_CMP, HEAP_SWAP, 20); + HEAP_INSERT(int, heap, n, MY_CMP, HEAP_SWAP, 10); + HEAP_INSERT(int, heap, n, MY_CMP, HEAP_SWAP, 30); // Remove the minimum (10) - HEAP_DELMIN(int, heap, n, MY_CMP, HEAP_SWAP); + HEAP_DELETE_MIN(int, heap, n, MY_CMP, HEAP_SWAP); // Print the new minimum (20) printf("%d", heap[1]); - // Increase the minimum by 20 to 40 - heap[1] += 20; - HEAP_INCREASE(int, heap, n, MY_CMP, HEAP_SWAP, 1); + // Increase the minimum to 40 + HEAP_INCREASE(int, heap, n, MY_CMP, HEAP_SWAP, 1, 40); // Print the new minimum (30) printf("%d", heap[1]);