-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodes.c
More file actions
71 lines (65 loc) · 980 Bytes
/
nodes.c
File metadata and controls
71 lines (65 loc) · 980 Bytes
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
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "monty.h"
#include <string.h>
#include <ctype.h>
/**
* is_digit - checks if a string is intiger.
* @val: the string.
*
* Return: 1 on success.
*/
int is_digit(char *val)
{
int i = 0;
while (val[i] != '\0')
{
if (val[i] == '-' && i == 0)
{
i++;
continue;
}
if (isdigit(val[i]))
{
i++;
continue;
}
else
return (0);
}
return (1);
}
/**
* creat_node - creates a new node.
* @n: the value for the new node.
*
* Return: a pointer that is a new node.
*/
stack_t *creat_node(int n)
{
stack_t *temp;
temp = (stack_t *)malloc(sizeof(stack_t));
if (temp == NULL)
{
fprintf(stderr, "Error: malloc failed\n");
free_nodes();
exit(EXIT_FAILURE);
}
temp->next = NULL;
temp->prev = NULL;
temp->n = n;
return (temp);
}
/**
* free_nodes - frees all the allocated memory.
*/
void free_nodes(void)
{
stack_t *temp;
if (head == NULL)
return;
while (head != NULL)
{
temp = head;
head = head->next;
free(temp);
}
}