special sort for 5 ok

This commit is contained in:
hugogogo
2021-09-27 02:13:21 +02:00
parent bb2a08833a
commit 6a93eda973
15 changed files with 114 additions and 61 deletions

View File

@@ -31,7 +31,8 @@ SRCS = push_swap.c \
minisort.c \
minisort_by_rank.c \
minisort_2ways_bubble_sort.c \
special_sorts_3_5.c
special_sorts_3_5.c \
sort_utils.c
ODIR = ./builds

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
builds/sort_utils.o Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -14,9 +14,9 @@ typedef struct s_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
@@ -35,9 +35,8 @@ void ps_error(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 find_pivot(t_stack *list, int size);
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);
/*
** 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_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
*/
int find_biggest(t_stack *list, int size);
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 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);
/*
** minisort_2ways_bubble_sort.c
** minisort_2ways_bubble_sort.c // minisort_bubble.c
*/
void mark_sublist(t_stack *list);
int find_smallest(t_stack *list);
void sort_big(t_stack **a, t_stack **b, t_list *solution);
int find_smallest_bubble(t_stack *list);
void bubble_sort(t_stack **a, t_stack **b, t_list *solution);
/*
** print.c

BIN
push_swap

Binary file not shown.

View File

@@ -1,22 +1,5 @@
#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;
@@ -126,7 +109,7 @@ void recursif_sort(t_stack **a, t_stack **b, t_list *solution)
else
{
// sort_big(a, b, solution)
// bubble_sort(a, b, solution)
mini_sort(a, solution);
// minisort(a, solution);
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)
special_sort_3(a, solution);
/*
else if (sublist_size(*a) <= 5)
special_sort_5(a, b, solution);
*/
else
recursif_sort(a, b, solution);
}

View File

@@ -33,7 +33,7 @@ static int search_smaller(t_stack *stack, int *smaller)
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;

View File

@@ -1,28 +1,6 @@
#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)
{
t_stack *head;

View File

@@ -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 smallest;
@@ -36,7 +36,7 @@ int find_smallest(t_stack *list)
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 next;
@@ -47,7 +47,7 @@ void sort_big(t_stack **a, t_stack **b, t_list *solution)
while (--list_size >= 0)
{
i = 0;
next = find_smallest(*a);
next = find_smallest_bubble(*a);
if (next > 0)
while (++i < next)
ra(a, &solution);

63
srcs/sort_utils.c Normal file
View 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);
}

View File

@@ -27,9 +27,30 @@ void special_sort_3(t_stack **a, t_list *solution)
sa(a, &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);
}

View File

@@ -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 "${LIST[@]}"
OUTPUT=$(./$PRGM ${LIST[@]})
OUTPUT=`./$PRGM ${LIST[@]}`
COUNT=$(echo "$OUTPUT" | wc -l)
RESULT=$(echo "$OUTPUT" | ./checker ${LIST[@]})