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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
-
|
|
!
-
|
|
-
|
|
!
-
|
!
-
|
-
|
!
| #module "MSingleLinkedList" m_max, m_cur, m_head, m_entry, m_data, m_next, m_count
#define _NULL -1
#define _FREE 0
#define _USED 1
#define ALLOC_CNT 10
#modinit
m_max = ALLOC_CNT
m_cur = 0
dim m_entry, m_max
dim m_data, m_max
dim m_next, m_max
dim m_count, m_max
m_head = m_cur
m_entry(m_head) = _USED
m_next(m_head) = _NULL
return
#modfunc SLL_GetEntry
flag = 0
repeat m_max
m_cur++
if( m_cur >= m_max ): m_cur = 0
if( m_entry(m_cur) == _FREE ): flag = 1: break
loop
if( flag ): return m_cur
m_cur = m_max
m_max += ALLOC_CNT
m_entry(m_max-1) = _FREE
m_data(m_max-1) = _FREE
m_next(m_max-1) = _FREE
m_count(m_max-1) = _FREE
return m_cur
#modfunc SLL_Search int x, var l
p = m_next(m_head)
q = m_head
flag = 0
repeat
if( p == _NULL ): break
if( x == m_data(p) ): flag = 1: break
if( x < m_data(p) ): break
q = p
p = m_next(p)
loop
l = q
if( flag ): return p: else: return _NULL
#modfunc SLL_Insert int x
SLL_Search thismod, x, q: p = stat
if( p != _NULL ){
m_count(p)++
return
}
SLL_GetEntry thismod
new = stat
m_entry(new) = _USED
m_data(new) = x
m_count(new) = 1
m_next(new) = m_next(q)
m_next(q) = new
return
#modfunc SLL_Delete int x
SLL_Search thismod, x, q: p = stat
if( p != _NULL ){
m_count(p)--
if( m_count(p) == 0 ){
m_next(q) = m_next(p)
m_entry(p) = _FREE
}
}else{
mes "要素"+x+"は見つかりません"
}
return
#modfunc SLL_Enum
p = m_next(m_head)
repeat -1, 1
if( p == _NULL ): break
if( m_count(p) > 1 ){
logmes ""+cnt+":"+m_data(p)+"("+m_count(p)+")"
}else{
logmes ""+cnt+":"+m_data(p)
}
p = m_next(p)
loop
return
#global
|