lst merge, reverse
This commit is contained in:
parent
76ce1747bc
commit
70457d744a
8 changed files with 89 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
#ifndef LIBFT_H
|
#ifndef LIBFT_H
|
||||||
#define LIBFT_H
|
#define LIBFT_H
|
||||||
|
#include "libftprintf.h"
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
|
|
@ -97,6 +98,8 @@ t_list *ft_lst_filter(t_list *lst, void const *data_ref, t_list *(*f)(t_list *el
|
||||||
t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)());
|
t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)());
|
||||||
t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)());
|
t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)());
|
||||||
t_list *ft_lstpop(t_list **lst);
|
t_list *ft_lstpop(t_list **lst);
|
||||||
|
void ft_lst_merge(t_list **begin_list1, t_list *begin_list2);
|
||||||
|
void ft_lst_reverse(t_list **begin_list);
|
||||||
|
|
||||||
int ft_diff(void *a, void *b);
|
int ft_diff(void *a, void *b);
|
||||||
char *ft_strrev(char *str);
|
char *ft_strrev(char *str);
|
||||||
|
|
@ -105,4 +108,6 @@ char *ft_itoa_base(int nbr, char *base, char *flags);
|
||||||
char *ft_lltoa_base(long long nbr, char *base, char *flags);
|
char *ft_lltoa_base(long long nbr, char *base, char *flags);
|
||||||
char *ft_ulltoa_base(unsigned long long nbr, char *base);
|
char *ft_ulltoa_base(unsigned long long nbr, char *base);
|
||||||
char *ft_uitoa_base(unsigned int nbr, char *base);
|
char *ft_uitoa_base(unsigned int nbr, char *base);
|
||||||
|
|
||||||
|
void ft_strlsort(char **list, int size, int (*cmp)());
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,6 @@ t_fmt *ft_parse(char **format)
|
||||||
ft_fmt_simplify(fmt);
|
ft_fmt_simplify(fmt);
|
||||||
fmt->valid = ft_fmt_validate_conversion(fmt) ? 0 : 1;
|
fmt->valid = ft_fmt_validate_conversion(fmt) ? 0 : 1;
|
||||||
|
|
||||||
ft_fmt_print(fmt);
|
/* ft_fmt_print(fmt); */
|
||||||
return (fmt);
|
return (fmt);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ int ft_printf(const char *format, ...)
|
||||||
|
|
||||||
va_start(ap1, format);
|
va_start(ap1, format);
|
||||||
str = ft_strdup(format);
|
str = ft_strdup(format);
|
||||||
ft_putendl(format);
|
ft_bzero(final, 1000);
|
||||||
|
/* ft_putendl(format); */
|
||||||
while (*str)
|
while (*str)
|
||||||
{
|
{
|
||||||
if (*str == '%')
|
if (*str == '%')
|
||||||
|
|
|
||||||
28
libftasm/src/lst/ft_lst_merge.c
Normal file
28
libftasm/src/lst/ft_lst_merge.c
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_list_merge.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/14 13:50:32 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/08/16 20:49:02 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_merge(t_list **begin_list1, t_list *begin_list2)
|
||||||
|
{
|
||||||
|
t_list *list_ptr;
|
||||||
|
|
||||||
|
if (*begin_list1)
|
||||||
|
{
|
||||||
|
list_ptr = *begin_list1;
|
||||||
|
while (list_ptr->next)
|
||||||
|
list_ptr = list_ptr->next;
|
||||||
|
list_ptr->next = begin_list2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*begin_list1 = begin_list2;
|
||||||
|
}
|
||||||
29
libftasm/src/lst/ft_lst_reverse.c
Normal file
29
libftasm/src/lst/ft_lst_reverse.c
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_list_reverse.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/08/14 13:20:13 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/08/16 22:34:13 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lst_reverse(t_list **begin_list)
|
||||||
|
{
|
||||||
|
t_list *new_start;
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
new_start = NULL;
|
||||||
|
while (*begin_list)
|
||||||
|
{
|
||||||
|
tmp = (*begin_list)->next;
|
||||||
|
(*begin_list)->next = new_start;
|
||||||
|
new_start = *begin_list;
|
||||||
|
*begin_list = tmp;
|
||||||
|
}
|
||||||
|
*begin_list = new_start;
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ void ft_lsteadd(t_list **alst, t_list *new)
|
||||||
t_list *lst;
|
t_list *lst;
|
||||||
|
|
||||||
lst = *alst;
|
lst = *alst;
|
||||||
|
new->next = NULL;
|
||||||
if (lst)
|
if (lst)
|
||||||
{
|
{
|
||||||
while (lst->next)
|
while (lst->next)
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,10 @@ t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
||||||
while (lst)
|
while (lst)
|
||||||
{
|
{
|
||||||
elem = (*f)(lst);
|
elem = (*f)(lst);
|
||||||
/* printf("size=%zu\n", elem->content_size); */
|
if (elem)
|
||||||
/* printf("content=%i\n", *(int*)elem->content); */
|
elem = ft_lstnew(elem->content, elem->content_size);
|
||||||
/* fflush(stdout); */
|
|
||||||
elem = ft_lstnew(elem->content, elem->content_size);
|
|
||||||
/* printf("size=%zu\n", elem->content_size); */
|
|
||||||
/* printf("content=%i\n", *(int*)elem->content); */
|
|
||||||
/* fflush(stdout); */
|
|
||||||
ft_lsteadd(&out, elem);
|
ft_lsteadd(&out, elem);
|
||||||
lst = lst->next;
|
lst = lst->next;
|
||||||
}
|
}
|
||||||
/* ft_lst_print(out, &ft_putnbr); */
|
|
||||||
return (out);
|
return (out);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
libftasm/src/strl/ft_strlsort.c
Normal file
21
libftasm/src/strl/ft_strlsort.c
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_strlsort(char **list, int size, int (*cmp)())
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < size - 1)
|
||||||
|
{
|
||||||
|
if ((*cmp)(list[i], list[i + 1]) > 0)
|
||||||
|
{
|
||||||
|
tmp = list[i];
|
||||||
|
list[i] = list[i + 1];
|
||||||
|
list[i + 1] = tmp;
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue