-
Notifications
You must be signed in to change notification settings - Fork 0
/
maze_stack.c
40 lines (36 loc) · 978 Bytes
/
maze_stack.c
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
//
// Created by thgir on 11/02/2021.
//
#include <stdlib.h>
#include <stdio.h>
#include "maze_stack.h"
boxInStack_t* stack_push(box_t* currentBox, boxInStack_t* previousStackElement, const int* position)
{
boxInStack_t* newBox = NULL;
newBox = (boxInStack_t*) malloc(sizeof(boxInStack_t));
if (newBox == NULL) {
fprintf(stderr, "Impossible allocation for a box");
return NULL;
}
newBox->box = currentBox;
newBox->previous = previousStackElement;
for (int i = 0; i < 2; ++i) {
newBox->position[i] = position[i];
}
return newBox;
}
boxInStack_t* stack_pop(boxInStack_t* currentBox)
{
boxInStack_t * previous = currentBox->previous;
//free(currentBox);
return previous;
}
void free_stack(boxInStack_t* stack_top)
{
boxInStack_t* temp;
while(stack_top != NULL){
temp = stack_top;
stack_top = stack_top->previous;
free(temp);
}
}