special sort for 5 ok
This commit is contained in:
3
Makefile
3
Makefile
@@ -31,7 +31,8 @@ SRCS = push_swap.c \
|
|||||||
minisort.c \
|
minisort.c \
|
||||||
minisort_by_rank.c \
|
minisort_by_rank.c \
|
||||||
minisort_2ways_bubble_sort.c \
|
minisort_2ways_bubble_sort.c \
|
||||||
special_sorts_3_5.c
|
special_sorts_3_5.c \
|
||||||
|
sort_utils.c
|
||||||
|
|
||||||
|
|
||||||
ODIR = ./builds
|
ODIR = ./builds
|
||||||
|
|||||||
BIN
builds/algo.o
BIN
builds/algo.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
builds/sort_utils.o
Normal file
BIN
builds/sort_utils.o
Normal file
Binary file not shown.
Binary file not shown.
@@ -14,9 +14,9 @@ typedef struct s_stack
|
|||||||
} t_stack;
|
} t_stack;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** luke's algo
|
** algo_bubble_sort.c // sort_luke.c
|
||||||
*/
|
*/
|
||||||
int bubble_sort(t_stack **a, t_stack **b, t_list *solution);
|
int luke_bubble_sort(t_stack **a, t_stack **b, t_list *solution);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** pushswap.c
|
** pushswap.c
|
||||||
@@ -35,9 +35,8 @@ void ps_error(int i);
|
|||||||
void ps_stop(t_stack *stack, t_list *lst, int i);
|
void ps_stop(t_stack *stack, t_list *lst, int i);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** algo.c
|
** algo.c // sort.c
|
||||||
*/
|
*/
|
||||||
int sublist_size(t_stack *list);
|
|
||||||
int nbr_element_smaller(t_stack *list, int size, int pivot);
|
int nbr_element_smaller(t_stack *list, int size, int pivot);
|
||||||
int find_pivot(t_stack *list, int size);
|
int find_pivot(t_stack *list, int size);
|
||||||
int divide_a(t_stack **a, t_stack **b, t_list *solution);
|
int divide_a(t_stack **a, t_stack **b, t_list *solution);
|
||||||
@@ -46,7 +45,18 @@ void send_sublist_to_a(t_stack **a, t_stack **b, t_list *solution);
|
|||||||
void hugo_sort(t_stack **a, t_stack **b, t_list *lst);
|
void hugo_sort(t_stack **a, t_stack **b, t_list *lst);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** spcecial_sorts_3_5.c
|
** sort_recursif.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** sort_utils.c
|
||||||
|
*/
|
||||||
|
int find_biggest(t_stack *list, int size);
|
||||||
|
int find_smallest(t_stack *list, int size);
|
||||||
|
int sublist_size(t_stack *list);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** spcecial_sorts_3_5.c // sort_specials_3_5.c
|
||||||
*/
|
*/
|
||||||
void special_sort_3(t_stack **a, t_list *solution);
|
void special_sort_3(t_stack **a, t_list *solution);
|
||||||
void special_sort_5(t_stack **a, t_stack **b, t_list *solution);
|
void special_sort_5(t_stack **a, t_stack **b, t_list *solution);
|
||||||
@@ -54,11 +64,10 @@ void special_sort_5(t_stack **a, t_stack **b, t_list *solution);
|
|||||||
/*
|
/*
|
||||||
** minisort.c
|
** minisort.c
|
||||||
*/
|
*/
|
||||||
int find_biggest(t_stack *list, int size);
|
|
||||||
void minisort(t_stack **list, t_list *solution);
|
void minisort(t_stack **list, t_list *solution);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** minisort_by_rank.c
|
** minisort_by_rank.c // minisort_rank.c
|
||||||
*/
|
*/
|
||||||
int find_rank(t_stack *list, int nbr, int i);
|
int find_rank(t_stack *list, int nbr, int i);
|
||||||
int order_is(t_stack *list, int nbr);
|
int order_is(t_stack *list, int nbr);
|
||||||
@@ -69,11 +78,11 @@ void sort_2(t_stack **a, t_list *solution);
|
|||||||
void mini_sort(t_stack **a, t_list *solution);
|
void mini_sort(t_stack **a, t_list *solution);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** minisort_2ways_bubble_sort.c
|
** minisort_2ways_bubble_sort.c // minisort_bubble.c
|
||||||
*/
|
*/
|
||||||
void mark_sublist(t_stack *list);
|
void mark_sublist(t_stack *list);
|
||||||
int find_smallest(t_stack *list);
|
int find_smallest_bubble(t_stack *list);
|
||||||
void sort_big(t_stack **a, t_stack **b, t_list *solution);
|
void bubble_sort(t_stack **a, t_stack **b, t_list *solution);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** print.c
|
** print.c
|
||||||
|
|||||||
21
srcs/algo.c
21
srcs/algo.c
@@ -1,22 +1,5 @@
|
|||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
// size is initialized to 1 because the loop check the next element, so it will end one step before reaching it
|
|
||||||
// it checks the next one to avoid handle the first one with ->limit set to 1
|
|
||||||
int sublist_size(t_stack *list)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
|
|
||||||
if (list == NULL)
|
|
||||||
return (0);
|
|
||||||
size = 1;
|
|
||||||
while (list->next != NULL && list->next->limit != 1)
|
|
||||||
{
|
|
||||||
list = list->next;
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
|
|
||||||
int nbr_element_smaller(t_stack *list, int size, int pivot)
|
int nbr_element_smaller(t_stack *list, int size, int pivot)
|
||||||
{
|
{
|
||||||
int nbr;
|
int nbr;
|
||||||
@@ -126,7 +109,7 @@ void recursif_sort(t_stack **a, t_stack **b, t_list *solution)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
// sort_big(a, b, solution)
|
// bubble_sort(a, b, solution)
|
||||||
mini_sort(a, solution);
|
mini_sort(a, solution);
|
||||||
// minisort(a, solution);
|
// minisort(a, solution);
|
||||||
if (sublist_size(*b) > 4)
|
if (sublist_size(*b) > 4)
|
||||||
@@ -143,10 +126,8 @@ void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
|
|||||||
{
|
{
|
||||||
if (sublist_size(*a) <= 3)
|
if (sublist_size(*a) <= 3)
|
||||||
special_sort_3(a, solution);
|
special_sort_3(a, solution);
|
||||||
/*
|
|
||||||
else if (sublist_size(*a) <= 5)
|
else if (sublist_size(*a) <= 5)
|
||||||
special_sort_5(a, b, solution);
|
special_sort_5(a, b, solution);
|
||||||
*/
|
|
||||||
else
|
else
|
||||||
recursif_sort(a, b, solution);
|
recursif_sort(a, b, solution);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ static int search_smaller(t_stack *stack, int *smaller)
|
|||||||
return (i_small);
|
return (i_small);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bubble_sort(t_stack **a, t_stack **b, t_list *solution)
|
int luke_bubble_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||||
{
|
{
|
||||||
int smaller;
|
int smaller;
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,6 @@
|
|||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int find_biggest(t_stack *list, int size)
|
|
||||||
{
|
|
||||||
int biggest;
|
|
||||||
int position;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
biggest = list->n;
|
|
||||||
position = 1;
|
|
||||||
i = 1;
|
|
||||||
while (list && --size)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
list = list->next;
|
|
||||||
if (biggest < list->n)
|
|
||||||
{
|
|
||||||
position = i;
|
|
||||||
biggest = list->n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (position);
|
|
||||||
}
|
|
||||||
|
|
||||||
void push_biggest(t_stack **list, t_list *solution, int size, int big)
|
void push_biggest(t_stack **list, t_list *solution, int size, int big)
|
||||||
{
|
{
|
||||||
t_stack *head;
|
t_stack *head;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ void mark_sublist(t_stack *list)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int find_smallest(t_stack *list)
|
int find_smallest_bubble(t_stack *list)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int smallest;
|
int smallest;
|
||||||
@@ -36,7 +36,7 @@ int find_smallest(t_stack *list)
|
|||||||
return (position);
|
return (position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sort_big(t_stack **a, t_stack **b, t_list *solution)
|
void bubble_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||||
{
|
{
|
||||||
int list_size;
|
int list_size;
|
||||||
int next;
|
int next;
|
||||||
@@ -47,7 +47,7 @@ void sort_big(t_stack **a, t_stack **b, t_list *solution)
|
|||||||
while (--list_size >= 0)
|
while (--list_size >= 0)
|
||||||
{
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
next = find_smallest(*a);
|
next = find_smallest_bubble(*a);
|
||||||
if (next > 0)
|
if (next > 0)
|
||||||
while (++i < next)
|
while (++i < next)
|
||||||
ra(a, &solution);
|
ra(a, &solution);
|
||||||
|
|||||||
63
srcs/sort_utils.c
Normal file
63
srcs/sort_utils.c
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
// size is initialized to 1 because the loop check the next element, so it will end one step before reaching it
|
||||||
|
// it checks the next one to avoid handle the first one with ->limit set to 1
|
||||||
|
int sublist_size(t_stack *list)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
|
||||||
|
if (list == NULL)
|
||||||
|
return (0);
|
||||||
|
size = 1;
|
||||||
|
while (list->next != NULL && list->next->limit != 1)
|
||||||
|
{
|
||||||
|
list = list->next;
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
|
|
||||||
|
int find_smallest(t_stack *list, int size)
|
||||||
|
{
|
||||||
|
int smallest;
|
||||||
|
int position;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
smallest = list->n;
|
||||||
|
position = 1;
|
||||||
|
i = 1;
|
||||||
|
while (list && --size)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
list = list->next;
|
||||||
|
if (smallest > list->n)
|
||||||
|
{
|
||||||
|
position = i;
|
||||||
|
smallest = list->n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (position);
|
||||||
|
}
|
||||||
|
|
||||||
|
int find_biggest(t_stack *list, int size)
|
||||||
|
{
|
||||||
|
int biggest;
|
||||||
|
int position;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
biggest = list->n;
|
||||||
|
position = 1;
|
||||||
|
i = 1;
|
||||||
|
while (list && --size)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
list = list->next;
|
||||||
|
if (biggest < list->n)
|
||||||
|
{
|
||||||
|
position = i;
|
||||||
|
biggest = list->n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (position);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -27,9 +27,30 @@ void special_sort_3(t_stack **a, t_list *solution)
|
|||||||
sa(a, &solution);
|
sa(a, &solution);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void special_sort_5(t_stack **a, t_stack **b, t_list *solution)
|
void special_sort_5(t_stack **a, t_stack **b, t_list *solution)
|
||||||
{
|
{
|
||||||
}
|
int size;
|
||||||
*/
|
int position;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
size = sublist_size(*a);
|
||||||
|
i = size - 3;
|
||||||
|
while (size > 3)
|
||||||
|
{
|
||||||
|
position = find_smallest(*a, size);
|
||||||
|
if (size - position >= position - 1)
|
||||||
|
{
|
||||||
|
while(--position)
|
||||||
|
ra(a, &solution);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while(position++ <= size)
|
||||||
|
rra(a, &solution);
|
||||||
|
pb(b, a, &solution);
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
special_sort_3(a, solution);
|
||||||
|
while (i--)
|
||||||
|
pa(a, b, &solution);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ LIST=($(shuf -i 0-$RANGE -n $SIZE))
|
|||||||
echo -e "${WHITE}test lancé avec la liste de nombres suivantes :${NC}"
|
echo -e "${WHITE}test lancé avec la liste de nombres suivantes :${NC}"
|
||||||
echo -e "${LIST[@]}"
|
echo -e "${LIST[@]}"
|
||||||
|
|
||||||
OUTPUT=$(./$PRGM ${LIST[@]})
|
OUTPUT=`./$PRGM ${LIST[@]}`
|
||||||
COUNT=$(echo "$OUTPUT" | wc -l)
|
COUNT=$(echo "$OUTPUT" | wc -l)
|
||||||
RESULT=$(echo "$OUTPUT" | ./checker ${LIST[@]})
|
RESULT=$(echo "$OUTPUT" | ./checker ${LIST[@]})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user