Skip to content
Snippets Groups Projects
Commit 1dec4649 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

Merge branch '12-add-print-function' into 'main'

Add stack_print(stack) function

See merge request !12
parents c5ad82a3 5a8d23e3
Branches
No related tags found
1 merge request!12Add stack_print(stack) function
...@@ -17,6 +17,20 @@ void stack_peek(stack s, int *value){ ...@@ -17,6 +17,20 @@ void stack_peek(stack s, int *value){
} }
} }
void stack_print(const stack s) {
//TODO: replace if statement with following as soon as relevant function is implemented
//if (!stack_is_empty()) {
if (s.top >= 0) {
printf(" TOP\n--------------------\n");
for (int* spot = s.data + s.top; spot >= s.data; --spot) {
printf("%8d | %12d\n", spot - s.data, *spot);
}
printf("--------------------\n BOTTOM\n");
} else {
printf("STACK EMPTY\n");
}
}
void stack_clone(stack s, stack *clone) { void stack_clone(stack s, stack *clone) {
clone->top = s.top; clone->top = s.top;
clone->capacity = s.capacity; clone->capacity = s.capacity;
...@@ -24,4 +38,5 @@ void stack_clone(stack s, stack *clone) { ...@@ -24,4 +38,5 @@ void stack_clone(stack s, stack *clone) {
for (int i = 0; i <= s.top && i < s.capacity; i++) { for (int i = 0; i <= s.top && i < s.capacity; i++) {
clone->data[i] = s.data[i]; clone->data[i] = s.data[i];
} }
} }
\ No newline at end of file
...@@ -12,4 +12,6 @@ void stack_init(stack *stack); ...@@ -12,4 +12,6 @@ void stack_init(stack *stack);
void stack_peek(stack s, int *value); void stack_peek(stack s, int *value);
void stack_clone(stack s, stack *clone); void stack_clone(stack s, stack *clone);
void stack_print(const stack s);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment