-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaze_stack.c
More file actions
30 lines (27 loc) · 745 Bytes
/
Copy pathmaze_stack.c
File metadata and controls
30 lines (27 loc) · 745 Bytes
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
//
// 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;
}