-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct.c
More file actions
80 lines (70 loc) · 1.46 KB
/
struct.c
File metadata and controls
80 lines (70 loc) · 1.46 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
typedef struct
{
byte r;
byte c;
} Point;
typedef struct
{
byte moveCount;
byte moves[MAX_MOVE_COUNT];
} MoveArray;
typedef struct
{
byte count;
Point redArray[MAX_RED_PATCH];
} RedSet;
typedef struct
{
Point cur;
Point robot;
MoveArray moveArray;
byte v;
} Element;
typedef struct
{
byte top;
Element data[MAX_STACK_SIZE];
} Stack;
void initStack(Stack *s);
int isEmpty(Stack *s);
int isFull(Stack *s);
void push(Stack *s, Element e);
void pop(Stack *s, Element &e);
void initStack(Stack *s)
{
s->top=-1;
}
int isFull(Stack *s)
{
return (s->top == (MAX_STACK_SIZE - 1));
}
int isEmpty(Stack *s)
{
return (s->top == -1);
}
void push(Stack *s, Element e)
{
if(isFull(s)) return;
(s->top)++;
s->data[s->top].cur.r = e.cur.r;
s->data[s->top].cur.c = e.cur.c;
s->data[s->top].robot.r = e.robot.r;
s->data[s->top].robot.c = e.robot.c;
s->data[s->top].moveArray.moveCount = e.moveArray.moveCount;
for (int i = 0; i < s->data[s->top].moveArray.moveCount; i++)
s->data[s->top].moveArray.moves[i] = e.moveArray.moves[i];
s->data[s->top].v = e.v;
}
void pop(Stack *s, Element &e)
{
if(isEmpty(s)) return;
e.cur.r = s->data[s->top].cur.r;
e.cur.c = s->data[s->top].cur.c;
e.robot.r = s->data[s->top].robot.r;
e.robot.c = s->data[s->top].robot.c;
e.moveArray.moveCount = s->data[s->top].moveArray.moveCount;
for (int i = 0; i < e.moveArray.moveCount; i++)
e.moveArray.moves[i] = s->data[s->top].moveArray.moves[i];
e.v = s->data[s->top].v;
(s->top)--;
}