aboutsummaryrefslogtreecommitdiff
path: root/Computer_Science/data_structures/chapter_3/stack_array.c
diff options
context:
space:
mode:
Diffstat (limited to 'Computer_Science/data_structures/chapter_3/stack_array.c')
-rw-r--r--Computer_Science/data_structures/chapter_3/stack_array.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/Computer_Science/data_structures/chapter_3/stack_array.c b/Computer_Science/data_structures/chapter_3/stack_array.c
index 4c23334..57a7fad 100644
--- a/Computer_Science/data_structures/chapter_3/stack_array.c
+++ b/Computer_Science/data_structures/chapter_3/stack_array.c
@@ -3,15 +3,15 @@
#include "stack_array.h"
-#define EMPTY_TOS (-1);
-#define MIN_STACK_SIZE (5);
+#define EMPTY_TOS (-1)
+#define MIN_STACK_SIZE (5)
struct stack_record
{
int capacity;
int top_of_stack;
elem *array;
-}
+};
stack create_stack(int max_elements)
{
@@ -55,11 +55,11 @@ void make_empty(stack s)
void push(elem x, stack s)
{
- if(s->top_of_stack >= capacity)
+ if(s->top_of_stack >= s->capacity)
printf("full stack");
- else
+ else
s->array[++s->top_of_stack] = x;
-
+
}
elem top(stack s)
@@ -88,3 +88,14 @@ elem top_and_pop(stack s)
printf("empty stack");
return 0;
}
+
+int main()
+{
+ stack s = create_stack(100);
+ push(1, s);
+ push(2, s);
+ push(3, s);
+ printf("%d\n", top_and_pop(s));
+ printf("%d\n", top_and_pop(s));
+ return 0;
+}