add: strshift and lst_clear
This commit is contained in:
parent
6b07016f94
commit
776bb7dce2
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct s_lst
|
||||
{
|
||||
|
16
src/lst/lst_clear.c
Normal file
16
src/lst/lst_clear.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include "./lst.h"
|
||||
|
||||
void lst_clear(lst **root, void (*del)(void *))
|
||||
{
|
||||
lst* current = *root;
|
||||
lst* next;
|
||||
|
||||
while (current != NULL)
|
||||
{
|
||||
next = current->next;
|
||||
(*del)(current->content);
|
||||
free(current);
|
||||
current = next;
|
||||
}
|
||||
free(root);
|
||||
}
|
@ -6,7 +6,7 @@ void lst_iter(lst** root, void (*f)(void *))
|
||||
|
||||
while (current != NULL)
|
||||
{
|
||||
(*f)(current);
|
||||
(*f)(current->content);
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
void str_shift(char *str, int shift)
|
||||
{
|
||||
for (size_t i = 0; str[i] == '\0'; i++)
|
||||
size_t i = 0;
|
||||
while (str[i - shift - 1] != '\0')
|
||||
{
|
||||
|
||||
str[i] = str[i - shift];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user