-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopcodes_A.c
More file actions
106 lines (91 loc) · 1.65 KB
/
opcodes_A.c
File metadata and controls
106 lines (91 loc) · 1.65 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "monty.h"
/**
* push - pushes node to top of stack.
* @stack: pointer to head node pointer of stack
* @nline: line number.
*
* Return: NAIN.
*/
void push(stack_t **stack, unsigned int nline)
{
stack_t *temp;
if (stack == NULL)
{
fprintf(stderr, "L%d: stack not found\n", nline);
exit(EXIT_FAILURE);
}
temp = malloc(sizeof(stack_t));
if (temp == NULL)
{
fprintf(stderr, "Error: malloc failed\n");
free_stack(stack);
exit(EXIT_FAILURE);
}
temp->next = *stack;
temp->prev = NULL;
temp->n = arg.arg;
if (*stack)
(*stack)->prev = temp;
*stack = temp;
}
/**
* pall - prints data of all nodes in stack.
* @stack: pointer to head node pointer of stack.
* @nline: line number.
*
* Return: nothing.
*/
void pall(stack_t **stack, unsigned int nline)
{
stack_t *temp;
(void)nline;
temp = *stack;
while (temp)
{
printf("%d\n", temp->n);
temp = temp->next;
}
}
/**
* free_stack - frees all nodes in a stack.
* @stack: pointer to head node pointer of a stack.
*
* Return: NAIN
*/
void free_stack(stack_t **stack)
{
stack_t *temp = NULL;
if (stack == NULL || *stack == NULL)
return;
while (*stack != NULL)
{
temp = (*stack)->next;
free(*stack);
*stack = temp;
}
}
/**
* nop - does NAIN.
* @stack: pointer to head node pointer of stack.
* @nline: line number.
*
* Return: NAIN.
*/
void nop(stack_t **stack, unsigned int nline)
{
(void)stack;
(void)nline;
}
/**
* _isalpha - checks if int is an alphabet.
* @c: int
*
* Return: 1 if yes, 0 otherwise.
*/
int _isalpha(int c)
{
if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')))
return (1);
else
return (0);
}