-
Notifications
You must be signed in to change notification settings - Fork 0
/
2015-2.c
92 lines (80 loc) · 1.86 KB
/
2015-2.c
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
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#include <stdlib.h>
struct window_node {
int id;
int rd_x;
int rd_y;
int lu_x;
int lu_y;
struct window_node *prev;
struct window_node *next;
};
struct window_node Tail;
struct window_node *Head = &Tail;
void insert_window(int id, int rd_x, int rd_y, int lu_x, int lu_y)
{
struct window_node *n = (struct window_node *)malloc(sizeof(struct window_node));
memset(n, 0, sizeof(struct window_node));
n->id = id;
n->rd_x = rd_x;
n->rd_y = rd_y;
n->lu_x = lu_x;
n->lu_y = lu_y;
n->prev = NULL;
n->next = Head;
Head->prev = n;
Head = n;
}
struct window_node * search_window(int x, int y)
{
struct window_node *tmp_node = &Tail;
while (tmp_node->prev != NULL) {
tmp_node = tmp_node->prev;
if ((x <= tmp_node->rd_x && x >= tmp_node->lu_x) &&
(y >= tmp_node->rd_y && y <= tmp_node->lu_y)) {
return tmp_node;
}
}
}
void click(int x, int y)
{
struct window_node *n = search_window(x, y);
if (n->prev != NULL) {
n->prev->next = n->next;
}
n->next->prev = n->prev;
n->prev = Tail.prev;
n->next = &Tail;
Tail.prev = n;
if (n->prev != NULL) {
n->prev->next = n;
}
}
void print_window()
{
struct window_node *tmp_node = &Tail;
while (tmp_node->prev != NULL) {
tmp_node = tmp_node->prev;
printf("%d ", tmp_node->id);
}
printf("\n");
}
int main() {
#if 1
insert_window(1, 5, 1, 1, 5);
insert_window(2, 7, 1, 3, 5);
click(1, 2);
click(4, 3);
click(6, 4);
#endif // 0
#if 0
insert_window(3, 5, 1, 1, 4);
insert_window(4, 7, 3, 3, 6);
insert_window(2, 8, 2, 4, 5);
click(5, 3); click(8, 4);
click(4, 4);
#endif // 0
print_window();
return 0;
}