aboutsummaryrefslogtreecommitdiff
path: root/src/algo/ft_heapsort.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/algo/ft_heapsort.c')
-rw-r--r--src/algo/ft_heapsort.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/algo/ft_heapsort.c b/src/algo/ft_heapsort.c
new file mode 100644
index 0000000..afd395d
--- /dev/null
+++ b/src/algo/ft_heapsort.c
@@ -0,0 +1,50 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_heapsort.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 02:59:22 by cacharle #+# #+# */
+/* Updated: 2020/02/10 03:57:50 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_algo.h"
+
+/* static void st_build_max_heap(void *base, size_t nel, size_t width, */
+/* int (*compar)(const void *, const void *)) */
+/* { */
+/* int i; */
+/* */
+/* i = 1; */
+/* while (i < nel) */
+/* { */
+/* compar(base + i * width, base + 2 * i * width) */
+/* */
+/* i++; */
+/* } */
+/* } */
+/* */
+/* static void st_heapify(void *base, size_t nel, size_t width, */
+/* int (*compar)(const void *, const void *)) */
+/* { */
+/* */
+/* } */
+
+int ft_heapsort(void *base, size_t nel, size_t width,
+ int (*compar)(const void *, const void *))
+{
+ /* size_t i; */
+ /* */
+ /* if (nel < 2) */
+ /* return (0); */
+ /* st_build_max_heap(base, nel, width, compar); */
+ /* i = -1; */
+ /* while (++i < nel) */
+ /* { */
+ /* ft_memswap(base, base + (nel - i - 1) * width); */
+ /* st_heapify(base, nel - i - 1, width, compar); */
+ /* } */
+ return (0);
+}