This commit is contained in:
Nathan Lebrun
2025-01-31 13:09:35 +01:00
parent 2367f6a42d
commit 304eeb73eb
8 changed files with 94 additions and 17 deletions

View File

@@ -28,14 +28,21 @@ t_node *create_node(char *val, t_token token)
return (node);
}
int add_node_back(t_node *head, char *val, t_token token)
int add_node_back(t_node **head, char *val, t_token token, t_pres pres)
{
if (!val)
return (0);
while (head->next != NULL)
head = head->next;
head->next = create_node(val, token);
if (head->next == NULL)
if (!(*head))
{
(*head) = create_node(val, token);
(*head)->pressision = pres;
return (1);
}
while ((*head)->next != NULL)
(*head) = (*head)->next;
(*head)->next = create_node(val, token);
(*head)->next->pressision = pres;
if ((*head)->next == NULL)
return (0);
return (1);
}

View File

@@ -27,7 +27,7 @@ static t_node *tokenize_base(char *str)
i = 1;
while (tab[i])
{
if (!add_node_back(head, tab[i], 0))
if (!add_node_back(&head, tab[i], 0, 0))
return (free(tab), NULL);
i++;
}

View File

@@ -50,7 +50,7 @@ typedef struct s_node
t_node *tokenize(char *str);
t_node *create_node(char *val, t_token token);
int add_node_back(t_node *head, char *val, t_token token);
int add_node_back(t_node **head, char *val, t_token token, t_pres pres);
int merge_with_next_node(t_node *node);
void free_linked_list(t_node *stack);
t_token get_token(char *str);