-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackOperations.h
48 lines (44 loc) · 1.25 KB
/
stackOperations.h
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
#include "stack.h"
/**
* Function that duplicates the first elements of the stack.
*/
void duplicate(STACK* s)
{
stackElem element = pop(s); /*!< Stores the element. */
push(s,element); /// Pushes once.
push(s,element); /// Pushes twice.
}
/**
* Function that swaps two elements in the stack.
*/
void swap(STACK *s)
{
stackElem x = pop(s); /*!< Stores an element in "x". */
stackElem y = pop(s); /*!< Stores the other in "y". */
push (s, x); /// Pushes "x".
push (s, y); /// Pushes "y".
}
/**
* Function that rotates the elements at the top of the stack.
*/
void rotateElements(STACK *s)
{
stackElem x = pop(s); /*!< Stores an element in "x". */
stackElem y = pop(s); /*!< Stores other in "y". */
stackElem z = pop(s); /*!< Stores the third in "z". */
push(s, y); /// Pushes "y".
push(s, x); /// Pushes "x".
push(s, z); /// Pushes "z"
}
/**
* Function that copies an element to the top of the stack.
*/
void copyElement(STACK* s)
{
stackElem element = pop(s); /*!< Stores the element that's on the top of the stack. */
if (element.elemType == Int)
{
int adress = s->sp - element.type.i;
push(s,s->stack[adress]); /// Pushes the element in the address to the top of the stack.
}
}