-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush_and_pall.c
More file actions
57 lines (50 loc) · 918 Bytes
/
Copy pathpush_and_pall.c
File metadata and controls
57 lines (50 loc) · 918 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
#include "monty.h"
unsigned int status;
/**
* _pall - prints a list of stacks
* @list: pointer to a stack_t lists
* @count: number of line number
*
* Return: no return
*/
void _pall(stack_t **list, unsigned int count)
{
stack_t *node, *head;
(void) count;
if (!list || !(*list))
return;
node = head = *list;
while (node)
{
fprintf(stdout, "%d\n", node->n);
node = node->next;
}
}
/**
* _push - adds a node to a list of stacks
* @list: pointer to a stack_t lists
* @count: number of line number
*
* Return: no return
*/
void _push(stack_t **list, unsigned int count)
{
stack_t *node = NULL;
(void) count;
node = malloc(sizeof(stack_t));
if (!node)
{
fprintf(stderr, "Error: malloc failed\n");
free_stack(list);
exit(EXIT_FAILURE);
}
node->prev = node->next = NULL;
if (!(*list))
(*list) = node;
else
{
(*list)->prev = node;
node->next = *list;
*list = node;
}
}