-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack_d.h
60 lines (46 loc) · 1.18 KB
/
stack_d.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#ifndef STACK_D
#define STACK_D
struct Stack_double // double stack
{
int top;
unsigned capacity;
double array[256];
};
struct Stack_double* createStack_d(unsigned capacity);
int isEmpty_d(struct Stack_double* stack);
double peek_d(struct Stack_double* stack);
double pop_d(struct Stack_double* stack);
void push_d(struct Stack_double* stack, double op);
struct Stack_double* createStack_d(unsigned capacity)
{
struct Stack_double* stack = malloc(sizeof(struct Stack_double));
if (!stack)
return NULL;
stack->top = -1;
stack->capacity = capacity;
//stack->array = malloc(stack->capacity *sizeof(int));
return stack;
}
int isEmpty_d(struct Stack_double* stack)
{
return stack->top == -1 ;
}
double peek_d(struct Stack_double* stack)
{
return stack->array[stack->top];
}
double pop_d(struct Stack_double* stack)
{
if (!isEmpty_d(stack))
return stack->array[stack->top--] ;
return -1.0000;
}
void push_d(struct Stack_double* stack, double op)
{
stack->array[++stack->top] = op;
}
#endif