aboutsummaryrefslogtreecommitdiff
path: root/test_mini/libft/src/algo/ft_qsort.c
diff options
context:
space:
mode:
authornass1pro <nass1pro@gmail.com>2020-06-12 13:52:58 +0200
committernass1pro <nass1pro@gmail.com>2020-06-13 11:45:50 +0200
commitd971bd8d16608f316396aba7a579d0b1f1af5aeb (patch)
tree98ec558582ed20a120e13b4a376fd206fb620da0 /test_mini/libft/src/algo/ft_qsort.c
parent3136f59540a8dd29e2f096be5a8943e2ddd28431 (diff)
downloadminishell-d971bd8d16608f316396aba7a579d0b1f1af5aeb.tar.gz
minishell-d971bd8d16608f316396aba7a579d0b1f1af5aeb.tar.bz2
minishell-d971bd8d16608f316396aba7a579d0b1f1af5aeb.zip
Added e_token enum
Diffstat (limited to 'test_mini/libft/src/algo/ft_qsort.c')
-rw-r--r--test_mini/libft/src/algo/ft_qsort.c64
1 files changed, 0 insertions, 64 deletions
diff --git a/test_mini/libft/src/algo/ft_qsort.c b/test_mini/libft/src/algo/ft_qsort.c
deleted file mode 100644
index 9bcfcdf..0000000
--- a/test_mini/libft/src/algo/ft_qsort.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_qsort.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/01/19 07:25:51 by cacharle #+# #+# */
-/* Updated: 2020/02/10 02:55:14 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft_algo.h"
-
-static t_ftrange ft_range_new(int lo, int hi)
-{
- t_ftrange range;
-
- range.lo = lo;
- range.hi = hi;
- return (range);
-}
-
-static int ft_qsort_partition(void *base, t_ftrange range,
- size_t width, t_ftcompar_func compar)
-{
- void *pivot;
- int p;
- int i;
-
- pivot = base + (range.hi * width);
- p = range.lo;
- i = range.lo - 1;
- while (++i < range.hi)
- {
- if (compar(base + (i * width), pivot) < 0)
- {
- ft_memswap(base + (i * width), base + (p * width), width);
- p++;
- }
- }
- ft_memswap(pivot, base + (p * width), width);
- return (p);
-}
-
-static void ft_qsort_rec(void *base, t_ftrange range,
- size_t width, t_ftcompar_func compar)
-{
- int pivot;
-
- if (range.lo >= range.hi)
- return ;
- pivot = ft_qsort_partition(base, range, width, compar);
- ft_qsort_rec(base, ft_range_new(range.lo, pivot - 1), width, compar);
- ft_qsort_rec(base, ft_range_new(pivot + 1, range.hi), width, compar);
-}
-
-void ft_qsort(void *base, size_t nel, size_t width,
- t_ftcompar_func compar)
-{
- if (width == 0 || nel < 2)
- return ;
- ft_qsort_rec(base, ft_range_new(0, nel - 1), width, compar);
-}