-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.h
More file actions
80 lines (65 loc) · 1.42 KB
/
Stack.h
File metadata and controls
80 lines (65 loc) · 1.42 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Stack.h:
* This module implements a stack (FIFO).
*
* Used to simulate recursion.
*/
#ifndef STACK_H_
#define STACK_H_
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/*
* This struct represents the list of parameters needed for a recursive call,
* in order to find number of solutions to a board (i.e. supports exhaustive backtracking).
*/
typedef struct{
int i;
int j;
int lastUsed;
} Parameters;
/*
* This struct represents a Stack Node.
*/
typedef struct stackNode{
Parameters params;
struct stackNode *next;
} StackNode;
/*
* This struct represent a stack.
*/
typedef struct {
StackNode *top;
} Stack;
/*
* Initializes an empty stack.
*/
Stack* initialize();
/*
* Pushes a Parameters object (created from function parameters) to the stack.
*/
void push(int i, int j, int lastUsed, Stack *stk);
/*
* Removes the top from the stack.
* @pre - stack is not empty.
*/
Parameters pop(Stack *stk);
/*
* Removes the top from the stack, inserts it's fields to the references of i, j, lastUsed.
* @pre - stack is not empty.
*/
void popAndUpdate(Stack *stk, int *i, int *j, int *lastUsed);
/*
* Returns the element at the top of the stack.
* @pre - stack is not empty.
*/
Parameters top(Stack *stk);
/*
* Removes stack and all it's elements, frees all memory resources.
*/
void destroyStack(Stack *stk);
/*
* Returns 1 iff the stack is empty.
*/
int isEmpty(Stack *stk);
#endif /* STACK_H_ */