summaryrefslogtreecommitdiff
path: root/rushs/tinyprintf/heap/add.c
diff options
context:
space:
mode:
Diffstat (limited to 'rushs/tinyprintf/heap/add.c')
-rw-r--r--rushs/tinyprintf/heap/add.c39
1 files changed, 0 insertions, 39 deletions
diff --git a/rushs/tinyprintf/heap/add.c b/rushs/tinyprintf/heap/add.c
deleted file mode 100644
index 78a4db8..0000000
--- a/rushs/tinyprintf/heap/add.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#include <stdlib.h>
-
-#include "heap.h"
-
-void heapify(int arr[], int n, int i)
-{
- if (i == 0)
- return;
- int parent = (i - 1) / 2;
- if (parent >= 0)
- {
- if (arr[i] > arr[parent])
- {
- int tmp = arr[i];
- arr[i] = arr[parent];
- arr[parent] = tmp;
- heapify(arr, n, parent);
- }
- }
-}
-
-void add(struct heap *heap, int val)
-{
- if (heap->size == heap->capacity)
- {
- heap->array = realloc(heap->array, heap->capacity * 2 * sizeof(int));
- if (heap->array == NULL)
- {
- free(heap);
- return;
- }
- heap->capacity *= 2;
- }
-
- heap->array[heap->size] = val;
- heap->size++;
-
- heapify(heap->array, heap->size, heap->size - 1);
-}