-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm_stack_func_1.c
More file actions
38 lines (33 loc) · 791 Bytes
/
Copy pathm_stack_func_1.c
File metadata and controls
38 lines (33 loc) · 791 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
#include "monty.h"
/**
* init_stack_elt - initializes a node for a struct stack_t.
* @n: The valuse to assign to the node element n.
* @next: The value to assigne to the node element next.
* @prev: The value to assigne to the node element prev.
*
* Return: The node address (success), NULL (faliure).
*/
stack_t *init_stack_elt(int n, stack_t *next, stack_t *prev)
{
stack_t *new = NULL;
new = monty_malloc(sizeof(stack_t));
if (new == NULL)
return (NULL);
new->n = n;
new->prev = prev;
new->next = next;
return (new);
}
/**
* stack_len - measures the length of a stack_t list type.
* @h: The head of the list.
*
* Return: The length of the list.
*/
size_t stack_len(const stack_t *h)
{
size_t len;
for (len = 0; h != NULL; h = h->next)
len++;
return (len);
}