-
Notifications
You must be signed in to change notification settings - Fork 0
/
232.c
83 lines (74 loc) · 1.64 KB
/
232.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
// http://www.bjfuacm.com/problem/232/
#include <stdio.h>
#include <stdlib.h>
struct Node;
typedef struct Node LinkedList;
typedef struct Node* PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;
typedef int ElementType;
struct Node {
ElementType val;
Position next;
};
List InitList(List L, int len) {
L = (PtrToNode)calloc(1, sizeof(LinkedList));
L->next = NULL;
List prev = L;
List post;
for (int i = 0; i < len; i++) {
post = (PtrToNode)calloc(1, sizeof(LinkedList));
scanf("%d", &post->val);
post->next = NULL;
prev->next = post;
prev = post;
}
return L;
}
Position Delete(Position prev) {
Position to_delete = prev->next;
Position state = prev;
prev->next = to_delete->next;
free(to_delete);
return state;
}
Position FindPrev(List L, Position p) {
Position prev = L;
while (prev->next != p) {
prev = prev->next;
}
return prev;
}
void DestroyList(List L) {
Position p;
p = L->next;
L->next = NULL;
while (p != NULL) {
free(p);
p = p->next;
}
}
int main() {
List L;
int len;
int x, y;
while (1) {
scanf("%d", &len);
if (len == 0) break;
L = InitList(L, len);
scanf("%d %d", &x, &y);
Position p = L->next;
while (p) {
if (p->val >= x && p->val <= y) p = Delete(FindPrev(L, p));
p = p->next;
}
p = L->next;
while (p) {
printf("%d", p->val);
printf("%s", p->next == NULL ? "\n" : " ");
p = p->next;
}
DestroyList(L);
free(L);
}
}