-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.c
58 lines (46 loc) · 877 Bytes
/
tools.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "monty.h"
/**
* isValidInteger - Checks if the string contain an integer
* @string: String to be parsed
*
* Return: 1 if the string is int else 0
*/
int isValidInteger(char *string)
{
char *endptr;
strtol(string, &endptr, 10);
if (*endptr != '\0' || string == endptr)
return (0);
return (1);
}
/**
* free_list - free the list
*
* Return: Void
*/
void free_list(void)
{
stack_t *curr = globals.head, *helper;
while (curr != NULL)
{
helper = curr;
curr = curr->next;
free(helper);
}
globals.head = NULL;
}
/**
* add_at_bottom - add the given node at the bottom of a doubly list
* @new: The pointer to the newly created node
*
* Return: Void
*/
void add_at_bottom(stack_t *new)
{
stack_t *current = globals.head;
new->prev = NULL;
new->next = current;
current->prev = new;
globals.head = new;
globals.opcode_arg = NULL;
}