-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopcode_fns_2.c
67 lines (58 loc) · 1.38 KB
/
opcode_fns_2.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "monty.h"
#include "structs.h"
#include <stdio.h>
/**
* _swap - Fuction that swaps the top two
* element of the stack
*
* @stack: pointer to stack
* @line_number: line number
*/
void _swap(__attribute((unused))stack_t **stack,
__attribute((unused))unsigned int line_number)
{
int temp;
/*Return if stack is NULL of has only one node*/
if (gv->head == NULL || gv->head->next == NULL)
{
fprintf(stderr, "L%d: can't swap, stack too short\n",
gv->line_number);
kill(NULL);
}
temp = gv->head->n;
gv->head->n = gv->head->next->n;
gv->head->next->n = temp;
}
/**
* _add - Function that adds the top two
* elements of the stack
*
* @stack: pointer to stack
* @line_number: line number
*/
void _add(__attribute((unused))stack_t **stack,
__attribute((unused))unsigned int line_number)
{
stack_t *head = gv->head;
/*If stack is NULL of stack elements are less than 2*/
if (head == NULL || head->next == NULL)
{
fprintf(stderr, "L%d: can't add, stack too short\n",
gv->line_number);
kill(NULL);
}
/*sum values of first two node of list and store in second node*/
gv->head->next->n = head->n + head->next->n;
/*remove top element*/
_pop(&(gv->head), gv->line_number);
}
/**
* _nop - Fuction that does nothing
*
* @stack: pointer to stack
* @line_number: line number
*/
void _nop(__attribute((unused))stack_t **stack,
__attribute((unused))unsigned int line_number)
{
}