aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Liodden <eriklio@stud.ntnu.no>2018-01-03 00:08:33 +0100
committerErik Liodden <eriklio@stud.ntnu.no>2018-01-03 00:08:33 +0100
commit314fcabf2f6bb0f0e851ce4d28e78c9628a674ec (patch)
treeb414348bdd7e1dcea64582bd81019760bf15877c
parent9c5b24d6bc6c72a5a111432fe2f03acc6a955922 (diff)
downloadalgdat-314fcabf2f6bb0f0e851ce4d28e78c9628a674ec.tar.gz
add heap_length
call heap_length to get the length of the heap. example: struct heap h; heap_length(&h); /* return length of heap */
-rw-r--r--heap.c5
-rw-r--r--structure.h2
2 files changed, 7 insertions, 0 deletions
diff --git a/heap.c b/heap.c
index 9ef3945..3e192e7 100644
--- a/heap.c
+++ b/heap.c
@@ -142,6 +142,11 @@ void heap_max_heap_insert(struct heap *h, void *key)
h->log_length++;
}
+int heap_length(struct heap *h)
+{
+ return h->log_length;
+}
+
void heap_sort(void *base, size_t nel, size_t width,
int (*compar)(const void *, const void *))
{
diff --git a/structure.h b/structure.h
index 126dd41..c8e6743 100644
--- a/structure.h
+++ b/structure.h
@@ -4,6 +4,7 @@
* - stack
* - queue
* - linked list (llist)
+ * - heap
*
* Erik Liodden
*/
@@ -102,5 +103,6 @@ void heap_maximum(struct heap *h, void *elem_addr);
void heap_extract_max(struct heap *h, void *elem_addr);
void heap_increase_key(struct heap *h, int pos, void *key);
void heap_max_heap_insert(struct heap *h, void *key);
+int heap_length(struct heap *h);
#endif /* STRUCTURE_H */