-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_lib_function.c
More file actions
57 lines (50 loc) · 853 Bytes
/
Copy pathstack_lib_function.c
File metadata and controls
57 lines (50 loc) · 853 Bytes
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
/*
* stack_lib_function.c
*
* Created on: Jul. 10, 2020
* Author: christy
* Credits : Takis
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "stack_lib_function.h"
/* *************** FUNCTIONS ***************** */
/*
* stack_empty() implementation
*/
bool stack_empty(stack_t *s)
{
if ((s->top) == 0)
{
return true;
}
else
{
return false;
}
}
/*
* push() implementation
*/
void push(stack_t *s, int x)
{
s->data[(s->top)++] = x; /* equivalent to: s -> data [(s->top)] = x; (s->top)++; */
/* also equivalent to: (s->top)++; s -> data [(s->top)-1] = x; */
return;
}
/*
* pop() implementation
*/
int pop(stack_t *s)
{
if (stack_empty(s))
{
printf("underflow error!");
exit(EXIT_FAILURE);
}
else
{
return (*s).data[--(s->top)]; /* could also write: (s->data)[--(s->top)]; */
}
}