-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopcodes.c
51 lines (43 loc) · 900 Bytes
/
opcodes.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
#include "monty.h"
/**
* add_dnodeint - adds new node at beginning of a list
* @head: double pointer to the head of the stack.
* @n: data to be contained in the node.
* Return: Nothing
*/
void add_dnodeint(stack_t **head, unsigned int n)
{
stack_t *ptr;
if (!head)
{
exit(EXIT_FAILURE);
}
ptr = malloc(sizeof(stack_t));
if (!ptr)
{
fprintf(stderr, "Error: malloc failed");
exit(EXIT_FAILURE);
}
ptr->n = n;
ptr->next = *head;
ptr->prev = NULL;
if (*head)
(*head)->prev = ptr;
*head = ptr;
}
/**
* pall - function that prints all the elements of a dbly linked list
* @stack: double pointer to the head of a stack.
* @line_number: The line number where the function is called.
* Return: number of nodes
*/
void pall(stack_t **stack, unsigned int line_number)
{
stack_t *h = *stack;
(void) line_number;
while (h)
{
printf("%d\n", h->n);
h = h->next;
}
}