163 lines
3.9 KiB
C
163 lines
3.9 KiB
C
#include "libs/libft/includes/libft.h"
|
|
#include <stdio.h>
|
|
|
|
void lst_print(void *element)
|
|
{
|
|
printf("lst->element : %s - %p\n",(char *)element, element);
|
|
}
|
|
|
|
void lst_delete(void *element)
|
|
{
|
|
free(element);
|
|
}
|
|
|
|
int lst_comp_ptr(void *to_find, void *to_compare)
|
|
{
|
|
return (to_find == to_compare);
|
|
}
|
|
|
|
int lst_comp(void *to_find, void *to_compare)
|
|
{
|
|
return (!ft_strcmp((char *)to_find, (char *)to_compare));
|
|
}
|
|
|
|
void *lst_copy(void *to_copy)
|
|
{
|
|
char *copy;
|
|
|
|
copy = ft_memalloc(sizeof(char) * (ft_strlen(to_copy) + 1));
|
|
copy = ft_strcpy(copy, to_copy);
|
|
return (copy);
|
|
}
|
|
|
|
//
|
|
// ft_lstnew
|
|
// ft_lstadd_back
|
|
// ft_lstadd_front
|
|
// ft_lstclear
|
|
// ft_lstdelone
|
|
// ft_lstiter
|
|
// ft_lstlast
|
|
// ft_lstmap
|
|
// ft_lstsize
|
|
//
|
|
// ft_lstfind
|
|
// ft_lstremove
|
|
// ft_lstremove_next
|
|
//
|
|
// ft_lstcreate <--
|
|
// ft_lstpush_back <--
|
|
// ft_lstpush_front <--
|
|
// ft_lstloop <--
|
|
// ft_lstloop_back <--
|
|
// ft_lstbegin <--
|
|
// ft_lstend <--
|
|
// ft_lstfind <--
|
|
// ft_lstinsert <--
|
|
// ft_lsterase <--
|
|
// ft_lstfree <--
|
|
// ft_lstlen <--
|
|
// ft_lstcopy <--
|
|
//
|
|
|
|
int main(void)
|
|
{
|
|
t_list *toto = NULL;
|
|
t_list *tmp;
|
|
char *str;
|
|
char *str2;
|
|
int c = 'f';
|
|
|
|
///////////////////////////////////////////////////////////
|
|
printf("\npush back ------------\n");
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
str = ft_memalloc(2 * sizeof(char));
|
|
str[1] = '\0';
|
|
str[0] = c++;
|
|
ft_lstpush_back(&toto, ft_lstcreate(str));
|
|
}
|
|
printf("print forward --------\n");
|
|
ft_lstloop(toto, lst_print);
|
|
printf("print backward -------\n");
|
|
ft_lstloop_back(ft_lstend(toto), lst_print);
|
|
printf("len ------------------\n");
|
|
printf("%i\n", ft_lstlen(toto));
|
|
|
|
///////////////////////////////////////////////////////////
|
|
printf("\npush front -----------\n");
|
|
c = 'e';
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
str = ft_memalloc(2 * sizeof(char));
|
|
str[1] = '\0';
|
|
str[0] = c--;
|
|
ft_lstpush_front(&toto, ft_lstcreate(str));
|
|
}
|
|
printf("print forward --------\n");
|
|
ft_lstloop(toto, lst_print);
|
|
printf("print backward -------\n");
|
|
ft_lstloop_back(ft_lstend(toto), lst_print);
|
|
printf("len ------------------\n");
|
|
printf("%i\n", ft_lstlen(toto));
|
|
|
|
///////////////////////////////////////////////////////////
|
|
printf("\nfind -----------------\n");
|
|
tmp = ft_lstfind(toto, "e", lst_comp);
|
|
if (tmp)
|
|
lst_print(tmp->content);
|
|
|
|
///////////////////////////////////////////////////////////
|
|
printf("\ninsert ---------------\n");
|
|
str = ft_memalloc(2 * sizeof(char));
|
|
str[1] = '\0';
|
|
str[0] = 'E';
|
|
ft_lstinsert(tmp, ft_lstcreate(str));
|
|
printf("print from insert ----\n");
|
|
ft_lstloop(tmp, lst_print);
|
|
printf("print from begin -----\n");
|
|
ft_lstloop(toto, lst_print);
|
|
printf("print backward -------\n");
|
|
ft_lstloop_back(ft_lstend(toto), lst_print);
|
|
printf("len ------------------\n");
|
|
printf("%i\n", ft_lstlen(toto));
|
|
|
|
///////////////////////////////////////////////////////////
|
|
printf("\nerase ----------------\n");
|
|
ft_lsterase(ft_lstfind(toto, "E", lst_comp), lst_delete);
|
|
printf("print forward --------\n");
|
|
ft_lstloop(toto, lst_print);
|
|
printf("print backward -------\n");
|
|
ft_lstloop_back(ft_lstend(toto), lst_print);
|
|
printf("len ------------------\n");
|
|
printf("%i\n", ft_lstlen(toto));
|
|
|
|
///////////////////////////////////////////////////////////
|
|
printf("\nfree -----------------\n");
|
|
tmp = ft_lstfind(toto, "e", lst_comp);
|
|
ft_lstfree(tmp, lst_delete);
|
|
printf("print forward --------\n");
|
|
ft_lstloop(toto, lst_print);
|
|
printf("print backward -------\n");
|
|
ft_lstloop_back(ft_lstend(toto), lst_print);
|
|
printf("len ------------------\n");
|
|
printf("%i\n", ft_lstlen(toto));
|
|
|
|
///////////////////////////////////////////////////////////
|
|
printf("\ncopy -----------------\n");
|
|
tmp = ft_lstcopy(toto, lst_copy);
|
|
printf("print forward toto ---\n");
|
|
ft_lstloop(toto, lst_print);
|
|
printf("print forward tmp ----\n");
|
|
ft_lstloop(tmp, lst_print);
|
|
printf("len tmp --------------\n");
|
|
printf("%i\n", ft_lstlen(tmp));
|
|
ft_lstfree(tmp, lst_delete);
|
|
|
|
///////////////////////////////////////////////////////////
|
|
ft_lstfree(toto, lst_delete);
|
|
|
|
return (0);
|
|
}
|
|
|