-
Notifications
You must be signed in to change notification settings - Fork 0
/
myStack.h
69 lines (58 loc) · 929 Bytes
/
myStack.h
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
struct node
{
int x;
int y;
int px; //Parent vertex coordinates
int py;
struct node *next;
};
typedef struct node node;
struct node *top = NULL;
int stack_x, stack_y, p_x, p_y, counter = 0;
void push(int _x,int _y, int _px, int _py)
{
node *tmp = (struct node*)malloc(sizeof(node));
tmp -> x = _x;
tmp -> y = _y;
tmp -> px = _px;
tmp -> py = _py;
tmp -> next = top;
top = tmp;
//printf("\nPushed: [x,y] = [%d,%d]", stack_x, stack_y);
counter ++;
}
void pop()
{
node *tmp;
int n;
tmp = top;
stack_x = tmp->x;
stack_y = tmp->y;
p_x = tmp->px;
p_y = tmp->py;
top = top->next;
free(tmp);
counter--;
}
int Top_x()
{
int __x = top->x;
return __x;
}
int Top_y()
{
int __y = top->y;
return __y;
}
int Top_px()
{
return top->px;
}
int Top_py()
{
return top->px;
}
int IsEmpty(struct node* tmp)
{
return tmp==NULL ? 1 : 0;
}