-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.h
68 lines (64 loc) · 1.05 KB
/
stack.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef STACK_H_INCLUDED
#define STACK_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#define TYPE float
#define MAX_SIZE 100
typedef struct {
int top;
TYPE items [MAX_SIZE];
}Stack;
void initialize(Stack *s)
{
s->top = -1;
}
int size (Stack *s)
{
return s->top + 1;
}
int isFull(Stack *s)
{
if (size (s) == MAX_SIZE)
return 1;
else
return 0;
}
int isEmpty(Stack *s)
{
if (size (s) == 0)
return 1;
else
return 0;
}
void push (TYPE value, Stack *s)
{
if (!isFull(s)){
s->top += 1;
s->items[s->top] = value;
}
else
printf("\nError\n The stack is full!\n");
}
TYPE peak(Stack *s)
{
if (!isEmpty(s)){
return s->items[s->top];
}
else {
// printf("\nThe stack is Empty !");
return -1;
}
}
TYPE pop(Stack *s)
{
if (!isEmpty(s)){
TYPE value = s->items[s->top];
s->top -= 1;
return value;
}
else {
return -1; //error
// printf("\nThe stack is Empty!");
}
}
#endif // STACK_H_INCLUDED