-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
48 lines (43 loc) · 1.11 KB
/
stack.c
File metadata and controls
48 lines (43 loc) · 1.11 KB
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
41
42
43
44
45
46
47
48
/**
* @file stack.c
* @brief Stack functions for n-puzzle solver program
* @author Mitchell Clay
* @date 4/18/2020
**/
#include <stdbool.h>
#include "node.h"
#include "stack.h"
#include <stdio.h>
#include <stdlib.h>
void push(struct Node** node, struct Element** stack, bool debug) {
struct Element* element = (struct Element*)malloc(sizeof(struct Element));
element -> node = *node;
element -> next = *stack;
(*stack) = element;
}
struct Node* pop(struct Element** stack, bool debug) {
if (*stack != NULL) {
struct Node* node = (*stack) -> node;
struct Element* tempPtr = *stack;
*stack = (*stack) -> next;
free(tempPtr);
return node;
}
}
void top(struct Element* stack, unsigned puzzle_size, bool debug) {
if (stack != NULL) {
struct Node* node = stack -> node;
printf("Top element is: \n");
printNodeInfo(node, puzzle_size);
}
else {
printf("The stack is empty\n");
}
}
bool StackEmpty (struct Element* stack) {
bool empty = true;
if (stack != NULL) {
empty = false;
}
return empty;
}