-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.c
More file actions
48 lines (44 loc) · 846 Bytes
/
stack.c
File metadata and controls
48 lines (44 loc) · 846 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
/*
CS3500 - Software Engineering Project
Calculator using - Tokenizer, infix2postfix, code generator, VM
codegenerator.c
Karol Przestrzelski
Colin Kelleher
Jonathan Hanley
Liam de la Cour
*/
#include <stdlib.h>
#include <stdio.h>
#include "stack.h"
/*
Create new float stack
*/
fstack *FStack(){
fstack *s = (fstack *)malloc(sizeof(fstack));
s->list[s->size];
s->currentPosition = -1;
return s;
}
/*
Pop first element off FStack
If the stack is empty, return 0
*/
float pop(fstack *f){
if (f->currentPosition == -1)
return 0;
return f->list[f->currentPosition--];
}
/*
Push new item onto stack
*/
void push(fstack *f, float item){
f->list[++f->currentPosition] = item;
}
/*
Get length of stack
*/
int len(fstack *f){
if (f->currentPosition == -1)
return 0;
return f->currentPosition + 1;
}