fix: lst -> slist
This commit is contained in:
parent
93da2c9ca6
commit
14adc54215
16 changed files with 48 additions and 46 deletions
30
srcs/slist/ft_slist_insert.c
Normal file
30
srcs/slist/ft_slist_insert.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include "libft.h"
|
||||
|
||||
int ft_slist_insert(t_slist **lst, t_slist *node, int index)
|
||||
{
|
||||
t_slist *curr = *lst;
|
||||
t_slist *prev = NULL;
|
||||
int i = 0;
|
||||
|
||||
if (index < 0 || !node)
|
||||
return (-1);
|
||||
if (index == 0)
|
||||
{
|
||||
node->next = *lst;
|
||||
*lst = node;
|
||||
return (0);
|
||||
}
|
||||
while (curr && i < index)
|
||||
{
|
||||
prev = curr;
|
||||
curr = curr->next;
|
||||
i++;
|
||||
}
|
||||
if (i == index)
|
||||
{
|
||||
prev->next = node;
|
||||
node->next = curr;
|
||||
return 0;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue