Skip to content
Snippets Groups Projects
Commit 166b49ca authored by Jules Stähli's avatar Jules Stähli
Browse files

#11 Add stack_clone function

parent 94a4d62f
No related branches found
No related tags found
1 merge request!13Resolve "Add clone function"
This commit is part of merge request !13. Comments created here will be created in the context of that merge request.
...@@ -16,3 +16,12 @@ void stack_peek(stack s, int *value){ ...@@ -16,3 +16,12 @@ void stack_peek(stack s, int *value){
*value = s.data[s.top]; *value = s.data[s.top];
} }
} }
void stack_clone(stack s, stack *clone) {
clone->top = s.top;
clone->capacity = s.capacity;
clone->data = malloc(sizeof(int) * s.capacity);
for (int i = 0; i <= s.top && i < s.capacity; i++) {
clone->data[i] = s.data[i];
}
}
\ No newline at end of file
...@@ -10,5 +10,6 @@ typedef struct _stack { ...@@ -10,5 +10,6 @@ typedef struct _stack {
void stack_init(stack *stack); 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);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment