-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperation.c
More file actions
executable file
·100 lines (89 loc) · 1.64 KB
/
operation.c
File metadata and controls
executable file
·100 lines (89 loc) · 1.64 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
#include "main.h"
/**
* push - pushes a node to the top of stack
* @stack: pointer to the head node pointer of stack
* @nline: the line number
*
* Return: Nothing.
*/
void push(stack_t **stack, unsigned int nline)
{
stack_t *new;
if (stack == NULL)
{
fprintf(stderr, "L%d: stack not found\n", nline);
exit(EXIT_FAILURE);
}
new = malloc(sizeof(stack_t));
if (new == NULL)
{
fprintf(stderr, "Error: malloc failed\n");
free_stack(stack);
exit(EXIT_FAILURE);
}
new->next = *stack;
new->prev = NULL;
new->n = arg.arg;
if (*stack)
(*stack)->prev = new;
*stack = new;
}
/**
* pall - prints the data of all nodes in stack
* @stack: pointer to the head node pointer of stack
* @nline: the 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 the head node pointer of stack
*
* Return: Nothing.
*/
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 literally nothing
* @stack: pointer to the head node pointer of stack
* @nline: the line number
* Return: Nothing.
*/
void nop(stack_t **stack, unsigned int nline)
{
(void)stack;
(void)nline;
}
/**
* _isalpha - checks if int is in alphabet
* @c: int
* Return: 1 if yes, 0 if no
*/
int _isalpha(int c)
{
if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')))
return (1);
else
return (0);
}