-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed.json
230 lines (230 loc) · 763 KB
/
feed.json
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
{
"version": "https://jsonfeed.org/version/1",
"title": "诗岸梦行舟",
"subtitle": "分享计算机知识以及各种心得总结",
"icon": "https://735690757.github.io/images/favicon.ico",
"description": "愿世间所有的美好都得以祝愿",
"home_page_url": "https://735690757.github.io",
"items": [
{
"id": "https://735690757.github.io/English/xbbEnglish/",
"url": "https://735690757.github.io/English/xbbEnglish/",
"title": "英语笔记",
"date_published": "2024-11-08T03:00:00.000Z",
"content_html": "<h1 id=\"领航\"><a class=\"markdownIt-Anchor\" href=\"#领航\">#</a> 领航</h1>\n<div class=\"note primary no-icon\">\n<p><strong>核心内容来自颉斌斌老师</strong><br>\n<strong>版权问题请联系作者 QQ:735690757</strong></p>\n</div>\n<h1 id=\"阅读\"><a class=\"markdownIt-Anchor\" href=\"#阅读\">#</a> 阅读</h1>\n<h2 id=\"常考的隐含假设\"><a class=\"markdownIt-Anchor\" href=\"#常考的隐含假设\">#</a> 常考的隐含假设</h2>\n<table>\n<thead>\n<tr>\n<th>要素</th>\n<th>隐含假设</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>做了什么</td>\n<td>论述的主体有能力 / 条件可以做</td>\n</tr>\n<tr>\n<td>建议 / 应该去做一件事情</td>\n<td>这件事还没有做过,作者认为这件事合理</td>\n</tr>\n<tr>\n<td>为什么 + 观点</td>\n<td>观点成立</td>\n</tr>\n<tr>\n<td>一个措施有利,应该去做</td>\n<td>同时不会有更大的弊端</td>\n</tr>\n<tr>\n<td>一个措施不利,应该去做</td>\n<td>同时不会出现更大的利</td>\n</tr>\n<tr>\n<td>禁止做一件的事情</td>\n<td>这件事已经被做过</td>\n</tr>\n</tbody>\n</table>\n<h2 id=\"选项比错的依据\"><a class=\"markdownIt-Anchor\" href=\"#选项比错的依据\">#</a> 选项比错的依据</h2>\n<ol>\n<li>答案已知且唯一</li>\n<li>选项具有有限性(4 个)</li>\n</ol>\n<p>比出一个最佳选择即可,放弃求证每日一个选项的正确于错误</p>\n<p><strong>但,什么是最佳?</strong></p>\n<p>实际上,找对很难, <strong>比错比比对更加容易!</strong></p>\n<p><mark>选项比错是高效的做法</mark></p>\n<h2 id=\"比错的逻辑\"><a class=\"markdownIt-Anchor\" href=\"#比错的逻辑\">#</a> 比错的逻辑</h2>\n<p>依据精准定位,评估一个出错率最小的选项</p>\n<p>比选项👉相对性👉借助其他选项</p>\n<p>比错👉 比较四个选项错误率的大小</p>\n<p>出错率最小不是完全正确,放弃追求完全正确的执念,转变为 “接受最佳的选项” 的新认识。</p>\n<div class=\"note primary no-icon\">\n<p>When you have eliminated the impossible ,whatever remains,however improbable,must be the truth.</p>\n</div>\n<h2 id=\"精准定位选项比错\"><a class=\"markdownIt-Anchor\" href=\"#精准定位选项比错\">#</a> 精准定位 + 选项比错</h2>\n<h2 id=\"定位不到的解题思路\"><a class=\"markdownIt-Anchor\" href=\"#定位不到的解题思路\">#</a> 定位不到的解题思路</h2>\n<ol>\n<li>反向定位(判断选项信息正误)</li>\n<li>取反 / 取非</li>\n<li>原命题转逆否命题</li>\n<li>主题主旨</li>\n</ol>\n<h1 id=\"写作大作文\"><a class=\"markdownIt-Anchor\" href=\"#写作大作文\">#</a> 写作 (大作文)</h1>\n<h2 id=\"图画作文\"><a class=\"markdownIt-Anchor\" href=\"#图画作文\">#</a> 图画作文</h2>\n<h3 id=\"行文框架\"><a class=\"markdownIt-Anchor\" href=\"#行文框架\">#</a> 行文框架</h3>\n<h4 id=\"第一段2-3句\"><a class=\"markdownIt-Anchor\" href=\"#第一段2-3句\">#</a> 第一段(2-3 句)</h4>\n<ol>\n<li>引出主题</li>\n<li>描述图片</li>\n<li>评价图片(可有可无)</li>\n</ol>\n<h4 id=\"第二段5句\"><a class=\"markdownIt-Anchor\" href=\"#第二段5句\">#</a> 第二段(5 句)</h4>\n<ol>\n<li>重申主题 + 分析影响</li>\n<li>影响 1 + 研究调查</li>\n<li>影响 2 + 名人名言</li>\n</ol>\n<h4 id=\"第三段\"><a class=\"markdownIt-Anchor\" href=\"#第三段\">#</a> 第三段</h4>\n<ol>\n<li>升华主题</li>\n<li>建议措施</li>\n<li>展望未来(可有可无)</li>\n</ol>\n<h3 id=\"引出主题的句子选一个即可\"><a class=\"markdownIt-Anchor\" href=\"#引出主题的句子选一个即可\">#</a> 引出主题的句子(选一个即可)</h3>\n<p>The animated cartoon reminds its readers of the significance of (主题词).</p>\n<div class=\"note primary no-icon\">\n<p>看到这副生动的漫画,人们想到了(主题词)的重要性</p>\n</div>\n<p>Nothing can get us denying that (主题词), under any circumstances, tends to be of great/enormous importance.</p>\n<div class=\"note primary no-icon\">\n<p>不可否认,在任何情况下,(主题词)往往很重要</p>\n</div>\n<p>You will not miss thinking that (主题词) is playing an indispensable role in our life and work.</p>\n<div class=\"note primary no-icon\">\n<p>你一定会想到(主题词)在我们的生活和工作中的起着不可或缺的作用(背)</p>\n</div>\n<h3 id=\"描述图片的句子\"><a class=\"markdownIt-Anchor\" href=\"#描述图片的句子\">#</a> 描述图片的句子</h3>\n<p>The picture is mainly related to the case that (图片主要人物 / 事物) + (doing/done…), which can be a vivid expression of the topic.</p>\n<div class=\"note primary no-icon\">\n<p>这一图片主要和… 有关,该图是对主题词的生动表达(背)</p>\n</div>\n<h3 id=\"评价图片可有可无\"><a class=\"markdownIt-Anchor\" href=\"#评价图片可有可无\">#</a> 评价图片(可有可无)</h3>\n<p>What the drawer tries to convey has profound practical significance.</p>\n<div class=\"note primary no-icon\">\n<p>画家试图传达的信息具有深刻的现实意义。(可以背一下)</p>\n</div>\n<p>Simple as the picture looks, its implicit meaning should be thought–provoking.</p>\n<div class=\"note primary no-icon\">\n<p>尽管图片简单,但其内涵发人深省。</p>\n</div>\n<p>The cartoon, at first glance, seems to be simple, but the deep meaning behind it is worth pondering.</p>\n<div class=\"note primary no-icon\">\n<p>这幅漫画乍一看似乎很简单,但其深层含义值得深思。</p>\n</div>\n<h3 id=\"重申主题分析影响\"><a class=\"markdownIt-Anchor\" href=\"#重申主题分析影响\">#</a> 重申主题 + 分析影响</h3>\n<p>Considering the significance of(主题词), it is necessary to point out the far-reaching consequences behind it.</p>\n<div class=\"note primary no-icon\">\n<p>考虑到 (主题词) 的重要性,有必要指出其背后意义深远的影响。</p>\n</div>\n<p>There seems to be more than one direct or indirect effect involved in (主 题 词) , which none of us can fail to notice.</p>\n<div class=\"note primary no-icon\">\n<p>似乎不止一个直接或间接的影响与 (主题词) 有关,我们无法忽视这些影响。(背)</p>\n</div>\n<p>The effects that (主题词) can exert are obvious and within easy reach.</p>\n<div class=\"note primary no-icon\">\n<p>(主题词) 产生的影响显而易见,也是不难找到的。</p>\n</div>\n<h3 id=\"影响-1-调查研究\"><a class=\"markdownIt-Anchor\" href=\"#影响-1-调查研究\">#</a> 影响 1 + 调查研究</h3>\n<h4 id=\"万能理由先行\"><a class=\"markdownIt-Anchor\" href=\"#万能理由先行\">#</a> 万能理由先行</h4>\n<ol>\n<li>\n<p>成长 / 成功 / 发展</p>\n<ol>\n<li>个人话题:the growth /success/prospect of individual</li>\n<li>社会话题:the development of economy /society/culture /legal system /enviroment</li>\n</ol>\n</li>\n<li>\n<p>知识 / 阅历 / 机会</p>\n<ol>\n<li>acquire adequate knowledge and experience</li>\n</ol>\n</li>\n<li>\n<p>效率 / 便利 / 时间</p>\n<ol>\n<li>efficiency / convenience</li>\n</ol>\n</li>\n<li>\n<p>健康(身体和心理) / 压力 / 愉悦</p>\n<ol>\n<li>physical health / mental health</li>\n<li>pressure / stress / stain</li>\n<li>bring a lot of mental and physical pleasure</li>\n</ol>\n</li>\n</ol>\n<h4 id=\"分析影响\"><a class=\"markdownIt-Anchor\" href=\"#分析影响\">#</a> 分析影响</h4>\n<p>It is generally recognized that nothing is more important than (主题词) for (四大万能理由) .</p>\n<div class=\"note primary no-icon\">\n<p>人们普遍认为 (主题词) 对 (四大万能理由) 最重要。(背)</p>\n</div>\n<h4 id=\"调查研究\"><a class=\"markdownIt-Anchor\" href=\"#调查研究\">#</a> 调查研究</h4>\n<p>Depending upon a rough estimate of the relevant department, nearly 86.2% of the respondents hold the same view.</p>\n<div class=\"note primary no-icon\">\n<p>根据有关部门的粗略估计,近 86.2% 的受访者持相同观点。</p>\n<p>relevant department 可以替换为具体部门</p>\n</div>\n<p>A recent Internet questionnaire of the relevant department indicates that approximately 86.2% of the respondents hold the same view.</p>\n<div class=\"note primary no-icon\">\n<p>有关部门最近的一份互联网问卷显示,约 86.2% 的受访者持相同观点。(背)</p>\n</div>\n<h3 id=\"影响-2-名人名言\"><a class=\"markdownIt-Anchor\" href=\"#影响-2-名人名言\">#</a> 影响 2 + 名人名言</h3>\n<h4 id=\"分析影响-2\"><a class=\"markdownIt-Anchor\" href=\"#分析影响-2\">#</a> 分析影响</h4>\n<p>(主题词) contributes to/is conducive to/is responsible for (四大万能理由) .</p>\n<div class=\"note primary no-icon\">\n<p>(主题词) 有助于 (四大万能理由) 。</p>\n</div>\n<h4 id=\"名人名言\"><a class=\"markdownIt-Anchor\" href=\"#名人名言\">#</a> 名人名言</h4>\n<p>As Envduct Karryguess, director of community service at LA College in LitLingo, puts it, “(万能理由) , needless to say, enormous importance for us.”</p>\n<h3 id=\"升华主题\"><a class=\"markdownIt-Anchor\" href=\"#升华主题\">#</a> 升华主题</h3>\n<p>All these factors support a rational conclusion that great importance should be attached to (主题词)</p>\n<div class=\"note primary no-icon\">\n<p>所有这些因素都支持一个合理的结论,即应该对 (主题词) 给予重视。</p>\n</div>\n<h3 id=\"建议措施\"><a class=\"markdownIt-Anchor\" href=\"#建议措施\">#</a> 建议措施</h3>\n<p>Everyone should cultivate a better awareness of it and take practical actions.</p>\n<div class=\"note primary no-icon\">\n<p>每个人都应更好地意识到这一点,并采取实际行动。</p>\n</div>\n<p>Strict laws and disciplines can guarantee the smooth running of the society</p>\n<div class=\"note primary no-icon\">\n<p>严格的法律和纪律可以保证社会的平稳运行。</p>\n</div>\n<h3 id=\"展望未来可有可无\"><a class=\"markdownIt-Anchor\" href=\"#展望未来可有可无\">#</a> 展望未来(可有可无)</h3>\n<p>Only in this way would our life become more real and meaningful</p>\n<div class=\"note primary no-icon\">\n<p>只有这样,我们的生活才能变得更加真实和富有意义。</p>\n</div>\n<h3 id=\"原型\"><a class=\"markdownIt-Anchor\" href=\"#原型\">#</a> 原型</h3>\n<pre><code>\tYou will not miss thinking that (主题词) is playing an indispensable role in our life and work.The picture is mainly related to the case that ( 图片主要人物/事物 ) + (doing/done....), which can be a vivid expression of the topic.\n\tThere seems to be more than one direct or indirect effect involved in ( 主 题 词 ) , which none of us can fail to notice.It is generally recognized that nothing is more important than (主题词) for (四大万能理由) .A recent Internet questionnaire of the relevant department indicates that approximately 86.2% of the respondents hold the same view. (主题词) contributes to (四大万能理由) .As Envduct Karryguess, director of community service at LA College in LitLingo, puts it, “ (万能理由) , needless to say, enormous importance for us.”\n\tAll these factors support a rational conclusion that great importance should be attached to(主题词). Everyone should cultivate a better awareness of it and take practical actions.\n</code></pre>\n<p>原型净约 136 词</p>\n<h3 id=\"试写2005-partb-52\"><a class=\"markdownIt-Anchor\" href=\"#试写2005-partb-52\">#</a> 试写(2005. PartB. 52.)</h3>\n<pre><code>\tYou will not miss thinking that concern elderly is palying an indispensable role in our life and work. The picture is mainly related to the case that four children would not like to take care their father.\n\tThere seems to be more than one direct or indirect effect involed in concern elderly, which none of us can fail to notice, It is generally recognized that nothing is more important than concern elderly for bring a lot of mental and physical pleasure. A recent Internet questionnaire of the relevant department indicates that approximately 82.6% of the respondents hold the same view. concern elderly contributes to a happy old age. As Envduc Karry, director of community service at LA College in LitLingo, put it,"A happy old age ,needless to say, enormous importance for elderly."\n\tAll these factors support a rational conclusion that great importance should be attached to concern elderly. Everyone should cultivate a better awareness of it and take pratical actions.\n</code></pre>\n<p>试写仅为作者的练习,不是范文!不是范文!不是范文!可能不会拿到很高的分数,仅供参考。</p>\n<p>共 161 词,虽然针对 2005 年的要求有点捉襟见肘,但对于新标准来说还是游刃有余的。</p>\n<h2 id=\"图表作文\"><a class=\"markdownIt-Anchor\" href=\"#图表作文\">#</a> 图表作文</h2>\n<h3 id=\"行文框架-2\"><a class=\"markdownIt-Anchor\" href=\"#行文框架-2\">#</a> 行文框架</h3>\n<h4 id=\"第一段2-3句-2\"><a class=\"markdownIt-Anchor\" href=\"#第一段2-3句-2\">#</a> 第一段(2-3 句)</h4>\n<ol>\n<li>引出主题</li>\n<li>描述图表</li>\n<li>评价图表(可有可无)</li>\n</ol>\n<h4 id=\"第二段5句-2\"><a class=\"markdownIt-Anchor\" href=\"#第二段5句-2\">#</a> 第二段(5 句)</h4>\n<ol>\n<li>重申主题 + 分析原因</li>\n<li>原因 1 + 研究调查</li>\n<li>原因 2 + 名人名言</li>\n</ol>\n<h4 id=\"第三段-2\"><a class=\"markdownIt-Anchor\" href=\"#第三段-2\">#</a> 第三段</h4>\n<ol>\n<li>升华主题</li>\n<li>建议措施</li>\n<li>展望未来(可有可无)</li>\n</ol>\n<h3 id=\"引出主题\"><a class=\"markdownIt-Anchor\" href=\"#引出主题\">#</a> 引出主题</h3>\n<p>(主题)is clearly shown in the picture.</p>\n<div class=\"note primary no-icon\">\n<p>在图表中清楚的表示了(主题)</p>\n</div>\n<p>(主题)is what the chart tries to convey.</p>\n<div class=\"note primary no-icon\">\n<p>(主题) 是图表想要传达的信息</p>\n</div>\n<p>The chart,in an obvious way, speaks volumes about the phenomenon that (主题). (背)</p>\n<div class=\"note primary no-icon\">\n<p>这张图表显然表明了一个现象,即(主题)</p>\n</div>\n<p>The chart above demonstrates clearly that some changes have taken place in terms of(数据标题)</p>\n<div class=\"note primary no-icon\">\n<p>上图清楚地表明,在(数据标题)方面已经发生了一些变化。</p>\n</div>\n<h3 id=\"描述图表\"><a class=\"markdownIt-Anchor\" href=\"#描述图表\">#</a> 描述图表</h3>\n<h4 id=\"饼状图表格\"><a class=\"markdownIt-Anchor\" href=\"#饼状图表格\">#</a> 饼状图 / 表格</h4>\n<p>X accounts for the highest percentage at x% of (主题词),followed by B at y% and C ,z%. At the bottom of the chart, k% is regarded as D.</p>\n<div class=\"note primary no-icon\">\n<p>X 占了(主题词)的最高比例即 x%,紧接着是 B 占了 y%,C 占了 z%。D 占了图的最少的一部分,是 k%。</p>\n</div>\n<h4 id=\"柱状图折线图\"><a class=\"markdownIt-Anchor\" href=\"#柱状图折线图\">#</a> 柱状图 / 折线图</h4>\n<p>There was a (dramatic increase/a steep drop) in the number of (一个东西) from (数据)in (时间)to(数据) in (时间).</p>\n<div class=\"note primary no-icon\">\n<p>(一个东西的) 数据出现了急剧的上升 / 严重的的下降,从(时间)的(数据)到(时间)的(数据)。</p>\n</div>\n<h3 id=\"重申主题分析原因\"><a class=\"markdownIt-Anchor\" href=\"#重申主题分析原因\">#</a> 重申主题 + 分析原因</h3>\n<p>The reasons that caused the phenomenon are obvious and within easy reach.</p>\n<div class=\"note primary no-icon\">\n<p>导致这一现象的原因是显而易见的。</p>\n</div>\n<p>After observation and consideration, some reasons of (主题词) can be highlight as follows.</p>\n<div class=\"note primary no-icon\">\n<p>经过观察和考虑,将一些原因列举如下。(背)</p>\n</div>\n<h3 id=\"原因1研究调查\"><a class=\"markdownIt-Anchor\" href=\"#原因1研究调查\">#</a> 原因 1 + 研究调查</h3>\n<p>同图画作文</p>\n<h3 id=\"原因2名人名言\"><a class=\"markdownIt-Anchor\" href=\"#原因2名人名言\">#</a> 原因 2 + 名人名言</h3>\n<p>同图画作文</p>\n<h3 id=\"升华主题-2\"><a class=\"markdownIt-Anchor\" href=\"#升华主题-2\">#</a> 升华主题</h3>\n<p>同图画作文</p>\n<h3 id=\"建议措施-2\"><a class=\"markdownIt-Anchor\" href=\"#建议措施-2\">#</a> 建议措施</h3>\n<p>同图画作文</p>\n<h3 id=\"原型-2\"><a class=\"markdownIt-Anchor\" href=\"#原型-2\">#</a> 原型</h3>\n<pre><code>\tThe chart,in an obvious way, speaks volumes about the phenomenon that (主题).X accounts for the highest percentage at x% of (主题词),followed by B at y% and C ,z%. At the bottom of the chart, k% is regarded as D.\n\tAfter observation and consideration, some reasons of (主题词) can be highlight as follows.It is generally recognized that nothing is more important than (主题词) for (四大万能理由) .A recent Internet questionnaire of the relevant department indicates that approximately 86.2% of the respondents hold the same view. (主题词) contributes to (四大万能理由) .As Envduct Karryguess, director of community service at LA College in LitLingo, puts it, “ (万能理由) , needless to say, enormous importance for us.”\n\tAll these factors support a rational conclusion that great importance should be attached to(主题词). Everyone should cultivate a better awareness of it and take practical actions.\n</code></pre>\n<p>模板净含约 120 词</p>\n<h2 id=\"文字作文\"><a class=\"markdownIt-Anchor\" href=\"#文字作文\">#</a> 文字作文</h2>\n<h3 id=\"行文框架-3\"><a class=\"markdownIt-Anchor\" href=\"#行文框架-3\">#</a> 行文框架</h3>\n<h4 id=\"第一段\"><a class=\"markdownIt-Anchor\" href=\"#第一段\">#</a> 第一段</h4>\n<ol>\n<li>引出主题</li>\n<li>陈述作者观点和态度</li>\n<li>表明自己的观点</li>\n</ol>\n<h4 id=\"第二段\"><a class=\"markdownIt-Anchor\" href=\"#第二段\">#</a> 第二段</h4>\n<ol>\n<li>重申主题 + 分析原因 / 影响</li>\n<li>原因 1 / 影响 1 + 例子(调查研究)</li>\n<li>原因 2 / 影响 2 + 例子(名人名言)</li>\n</ol>\n<h4 id=\"第三段-3\"><a class=\"markdownIt-Anchor\" href=\"#第三段-3\">#</a> 第三段</h4>\n<ol>\n<li>升华主题</li>\n<li>建议措施</li>\n<li>展望未来(可有可无)</li>\n</ol>\n<h3 id=\"引出主题-2\"><a class=\"markdownIt-Anchor\" href=\"#引出主题-2\">#</a> 引出主题</h3>\n<p>The phenomenon mentioned in the above excerpt that (主题)is receiving more and more attention and hot discussion.</p>\n<div class=\"note primary no-icon\">\n<p>上述摘录中提到的现象(主题)正受到越来越多的关注并成为热点讨论话题。</p>\n</div>\n<h3 id=\"陈述作者观点和态度\"><a class=\"markdownIt-Anchor\" href=\"#陈述作者观点和态度\">#</a> 陈述作者观点和态度</h3>\n<p>As is presented in the excerpt , the author believes that… is of graet significance for …</p>\n<div class=\"note primary no-icon\">\n<p>如摘录所示,作者认为… 对… 具有重要意义</p>\n</div>\n<h3 id=\"表明自己的观点\"><a class=\"markdownIt-Anchor\" href=\"#表明自己的观点\">#</a> 表明自己的观点</h3>\n<p>As far as this question is concerned, I support the author’s view.</p>\n<div class=\"note primary no-icon\">\n<p>关于这个问题,我支持作者的观点。</p>\n</div>\n<h3 id=\"原因1研究调查-2\"><a class=\"markdownIt-Anchor\" href=\"#原因1研究调查-2\">#</a> 原因 1 + 研究调查</h3>\n<p>同图画作文</p>\n<h3 id=\"原因2名人名言-2\"><a class=\"markdownIt-Anchor\" href=\"#原因2名人名言-2\">#</a> 原因 2 + 名人名言</h3>\n<p>同图画作文</p>\n<h3 id=\"升华主题-3\"><a class=\"markdownIt-Anchor\" href=\"#升华主题-3\">#</a> 升华主题</h3>\n<p>同图画作文</p>\n<h3 id=\"建议措施-3\"><a class=\"markdownIt-Anchor\" href=\"#建议措施-3\">#</a> 建议措施</h3>\n<p>同图画作文</p>\n<h1 id=\"写作小作文\"><a class=\"markdownIt-Anchor\" href=\"#写作小作文\">#</a> 写作 (小作文)</h1>\n<h2 id=\"书信\"><a class=\"markdownIt-Anchor\" href=\"#书信\">#</a> 书信</h2>\n<h3 id=\"格式\"><a class=\"markdownIt-Anchor\" href=\"#格式\">#</a> 格式</h3>\n<pre><code>Dear_______,(<-逗号)\n\t\n\t第一段_____________________________________________\n\t第二段_____________________________________________\n\t第三段_____________________________________________\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(逗号->)\tyour sincerely,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLi Ming\n</code></pre>\n<h3 id=\"行文结构\"><a class=\"markdownIt-Anchor\" href=\"#行文结构\">#</a> 行文结构</h3>\n<h4 id=\"前置\"><a class=\"markdownIt-Anchor\" href=\"#前置\">#</a> 前置</h4>\n<p>称呼</p>\n<h4 id=\"第一段-2\"><a class=\"markdownIt-Anchor\" href=\"#第一段-2\">#</a> 第一段</h4>\n<ol>\n<li>表明身份(可有可无)+ 表明主题(重要)</li>\n</ol>\n<h4 id=\"第二段-2\"><a class=\"markdownIt-Anchor\" href=\"#第二段-2\">#</a> 第二段</h4>\n<ol>\n<li>展开主题 + 两点论</li>\n</ol>\n<h4 id=\"第三段-4\"><a class=\"markdownIt-Anchor\" href=\"#第三段-4\">#</a> 第三段</h4>\n<ol>\n<li>重申主题 + 寒暄(可有可无)</li>\n</ol>\n<h4 id=\"尾部\"><a class=\"markdownIt-Anchor\" href=\"#尾部\">#</a> 尾部</h4>\n<p>落款</p>\n<h3 id=\"万能身份\"><a class=\"markdownIt-Anchor\" href=\"#万能身份\">#</a> 万能身份</h3>\n<p>I am president of the Students’ Union</p>\n<h3 id=\"表明主题\"><a class=\"markdownIt-Anchor\" href=\"#表明主题\">#</a> 表明主题</h3>\n<p>I am writing the letter to you for the purpose of (目的,从”directions“中汲取。doing sth)</p>\n<h3 id=\"展开主题两点论\"><a class=\"markdownIt-Anchor\" href=\"#展开主题两点论\">#</a> 展开主题 + 两点论</h3>\n<p>参考万能主题</p>\n<h3 id=\"万能结尾\"><a class=\"markdownIt-Anchor\" href=\"#万能结尾\">#</a> 万能结尾</h3>\n<p>Please accept my sincere gratitude to you for reading the content above. If you need to know more about it, please contact me.</p>\n<h3 id=\"模板\"><a class=\"markdownIt-Anchor\" href=\"#模板\">#</a> 模板</h3>\n<pre><code>Dear_______,\n\tI am president of the Students' Union)(此处视情况变换身份). I am writing the letter to you for the purpose of (目的,从”directions“中汲取。doing sth).\n\tOf all the points concerned. I'd like to name the most significant ones as follows. First and foremost,______(要点一).Additionally,_______(要点二).(此处可再加一个要点"Not but not least")\n\tplease accept my sincere gratitude to you for reading the content above. If you need to know more about it, please contact me.\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tYours sincerely,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(name)\n</code></pre>\n<h2 id=\"通知\"><a class=\"markdownIt-Anchor\" href=\"#通知\">#</a> 通知</h2>\n<h2 id=\"备忘录\"><a class=\"markdownIt-Anchor\" href=\"#备忘录\">#</a> 备忘录</h2>\n<h1 id=\"翻译\"><a class=\"markdownIt-Anchor\" href=\"#翻译\">#</a> 翻译</h1>\n<h2 id=\"文章一\"><a class=\"markdownIt-Anchor\" href=\"#文章一\">#</a> 文章一</h2>\n<h3 id=\"原文\"><a class=\"markdownIt-Anchor\" href=\"#原文\">#</a> 原文</h3>\n<pre><code>\tWe tend to think that friends and family members are our biggest source of connection, laughter and warmth. While that may well be true, researchers have also recently found that interacting with strangers actually brings a boost in mood and feelings of belonging that we didn’t expect.\n\tIn one series of studies, researchers instructed Chicago-area commuters using public transportation to strike up a conversation with someone near them. On average, participants who followed this instruction felt better than those who had been told to stand or sit in silence. The researchers also argued that when we shy away from casual interactions with strangers, it is often due to a misplaced anxiety that they might not want to talk to us. Much of that time, however, this belief is false. As it turns out, many people are actually perfectly willing to talk and may even be flattered to receive your attention.\n</code></pre>\n<h3 id=\"逐句翻译\"><a class=\"markdownIt-Anchor\" href=\"#逐句翻译\">#</a> 逐句翻译</h3>\n<p>We tend to think that friends and family members are our biggest source of connection, laughter and warmth.</p>\n<div class=\"note info no-icon\">\n<p>我们往往会认为朋友和家庭成员是我们情感联系、欢声笑语以及幸福温暖的最大来源。</p>\n</div>\n<p>While that may well be true, researchers have also recently found that interacting with strangers actually brings a boost in mood and feelings of belonging that we didn’t expect.</p>\n<div class=\"note info no-icon\">\n<p>尽管那很肯能是真的,但最近研究者们发现与陌生人交往实际上会带来我们没有想到的情绪上的增长以及感觉上的促进(让人心情愉悦、有归属感)</p>\n</div>\n<p>In one series of studies, researchers instructed Chicago-area <ins>commuters</ins> using public transportation to strike up a conversation with someone near them</p>\n<div class=\"note info no-icon\">\n<p>在一系列研究中,研究者们让 Chicago 区域使用公共交通的通勤人员去努力和他们身边的人产生交流</p>\n</div>\n<p>On average, participants who followed this instruction felt better than those who had been told to stand or sit in silence.</p>\n<div class=\"note info no-icon\">\n<p>通常来讲,相较于被告知在安静中站着或者坐着的来说,参与者们跟随着这个指示来做会感觉到更好</p>\n</div>\n<p>The researchers also <ins>argued</ins> that when we shy away from casual interactions with strangers, it is often due to a <ins>misplaced</ins> anxiety that they might not want to talk to us.</p>\n<div class=\"note info no-icon\">\n<p>研究者们也认为,当我们在与陌生人随意的交谈而感到害羞跑开时,那通常是因为不合时宜的焦虑,那就是他们也许不想和我们讲话</p>\n</div>\n<p>Much of that time, however, this belief is false.</p>\n<div class=\"note info no-icon\">\n<p>然而,大多数情况下,这种想法是错误的</p>\n</div>\n<p>As it turns out, many people are actually perfectly willing to talk and may even be <ins>flattered</ins> to <ins>receive</ins> your attention.</p>\n<div class=\"note info no-icon\">\n<p>结果是,许多人实际上非常愿意交谈,甚至会因为得到你的关注而感到荣幸。</p>\n</div>\n<h3 id=\"词汇\"><a class=\"markdownIt-Anchor\" href=\"#词汇\">#</a> 词汇</h3>\n<table>\n<thead>\n<tr>\n<th>单词</th>\n<th>释义</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>flattered</td>\n<td>adj.(因受重视而)感到满意的,觉得荣幸的;(在正式场合表示感谢)不胜荣幸的,深感荣幸的<br /> v. 奉承;自命不凡;使显得漂亮,使显得出色(flattered 的过去式和过去分词)</td>\n</tr>\n<tr>\n<td>misplaced</td>\n<td>adj. 不合时宜的;(情感)寄托错的;放错位置的;暂时丢失的<br />v. 乱放(而找不到),暂时丢失;错放(misplace 的过去式和过去分词)</td>\n</tr>\n<tr>\n<td>argued</td>\n<td>v. 争论;争吵;争辩;论证;说理;显示出,表明(argue 的过去式和过去分词)</td>\n</tr>\n<tr>\n<td>commuters</td>\n<td>n. 通勤者;每日往返上班者(commuter 的复数)</td>\n</tr>\n<tr>\n<td>receive</td>\n<td>v. 得到,收到;遭受,经受(特定待遇);对…… 作出反应;接待,招待;接收(某人为成员);接收,收听(信号);(通过无线电)听到;购买,窝藏(赃物);接(球);领受(圣餐面包或葡萄酒);接受(治疗);形成(看法,印象);容纳,承接</td>\n</tr>\n</tbody>\n</table>\n<h2 id=\"文章二\"><a class=\"markdownIt-Anchor\" href=\"#文章二\">#</a> 文章二</h2>\n<h3 id=\"原文-2\"><a class=\"markdownIt-Anchor\" href=\"#原文-2\">#</a> 原文</h3>\n<pre><code>\tIn the late 18th century, William Wordsworth became famous for his poems about nature.And he was one of the founders of a movement called Romanticism, which celebrated the wonders of the natural world.\n\tPoetry is powerful. Its energy and rhythm can capture a reader, transport them to another world and make then see things differently. Through carefully selected words and phrases, poems can be dramatic, funny, beautiful, moving and inspiring.\n\tNo one knows for sure when poetry began but it has been around for thousands of years,even before people could write. It was a way to tell stories and pass down history. It is closely related to song and even when written it is usually created to be performed out loud. Poems really come to life when they are recited. This can also help with understanding them too, because the rhythm and sounds of the words become clearer\n</code></pre>\n<h3 id=\"逐句翻译-2\"><a class=\"markdownIt-Anchor\" href=\"#逐句翻译-2\">#</a> 逐句翻译</h3>\n<p>In the late 18th century, William Wordsworth became famous for his poems about nature.</p>\n<div class=\"note info no-icon\">\n<p>在 18 世纪后期,William Wordsworth 因他的有关自然的诗集而远近闻名。</p>\n</div>\n<p>And he was one of the founders of a movement called Romanticism, which celebrated the wonders of the natural world.</p>\n<div class=\"note info no-icon\">\n<p>他是万千浪漫主义运动奠基者的一员,专为自然世界而歌颂。</p>\n</div>\n<p>Poetry is powerful.</p>\n<div class=\"note info no-icon\">\n<p>诗歌满含力量。</p>\n</div>\n<p>Its energy and rhythm can capture a reader, transport them to another world and make then see things differently.</p>\n<div class=\"note info no-icon\">\n<p>这种能量和神话能够俘获读者芳心,带领他们进入另外一个世界,使之他们以不同的眼光看待世界。</p>\n</div>\n<p>Through carefully selected words and phrases, poems can be dramatic, funny, beautiful, moving and inspiring.</p>\n<div class=\"note info no-icon\">\n<p>通过在词汇和语段上的精挑细选,诗歌可以表现出戏剧的,有趣的、华丽的、感动的以及鼓舞人心的情感。</p>\n</div>\n<p>No one knows for sure when poetry began but it has been around for thousands of years,even before people could write.</p>\n<div class=\"note info no-icon\">\n<p>没有人确切地知道诗歌始于何时,但其确实萦绕千年之久,甚至在人们学会书写之前就已经出现了。</p>\n</div>\n<p>It was a way to tell stories and pass down history.</p>\n<div class=\"note info no-icon\">\n<p>这曾经是讲述故事和传承过去历史的一种方式</p>\n</div>\n<p>It is closely related to song and even when written it is usually created to be performed out loud.</p>\n<div class=\"note info no-icon\">\n<p>他与歌曲密切相关,即使写成它,它通常也是为了大声表演而创作的。</p>\n</div>\n<p>Poems really come to life when they are recited.</p>\n<div class=\"note info no-icon\">\n<p>诗歌吟诵时才正真背赋予了生命。</p>\n</div>\n<p>This can also help with understanding them too, because the rhythm and sounds of the words become clearer</p>\n<div class=\"note info no-icon\">\n<p>这也有助于理解它们,因为单词的节奏和声音变得更加清晰</p>\n</div>\n<h1 id=\"完型\"><a class=\"markdownIt-Anchor\" href=\"#完型\">#</a> 完型</h1>\n<h2 id=\"完型理论\"><a class=\"markdownIt-Anchor\" href=\"#完型理论\">#</a> 完型理论</h2>\n<ol>\n<li>其本质上仍然是比错</li>\n<li>亟需打破传统思维,摒弃完美理解</li>\n<li>追求文章内部的一致性</li>\n<li>主旨一致</li>\n</ol>\n<h3 id=\"局部一致性全局一致性\"><a class=\"markdownIt-Anchor\" href=\"#局部一致性全局一致性\">#</a> 局部一致性 + 全局一致性</h3>\n<ol>\n<li>上下文语义一致</li>\n<li>注意逻辑合理(逻辑改变方向还是保持方向?)(二分法)</li>\n</ol>\n",
"tags": [
"English",
"英语"
]
},
{
"id": "https://735690757.github.io/DSLearnNote/DSErrorProneSummary/",
"url": "https://735690757.github.io/DSLearnNote/DSErrorProneSummary/",
"title": "数据结构之与错题博弈",
"date_published": "2024-10-30T03:00:00.000Z",
"content_html": "<h1 id=\"错题是回忆的老师\"><a class=\"markdownIt-Anchor\" href=\"#错题是回忆的老师\">#</a> 错题是回忆的老师</h1>\n<h1 id=\"时间复杂度\"><a class=\"markdownIt-Anchor\" href=\"#时间复杂度\">#</a> 时间复杂度</h1>\n<ol class=\"options\">\n<li class=\"quiz\">假设一个有 n 个顶点和 e 条弧的有向图,用邻接表表示,则删除与某个顶点 vi 相关的所有弧,则时间复杂度为?\n<ul class=\"options\">\n<li><code>O(n)</code></li>\n<li class=\"correct\"><code>O(n+e)</code> </li>\n<li><code>O(e);</code></li>\n<li><code>O(n*e);</code></li>\n</ul>\n<blockquote>\n<p>第一步找到 Vi, 删除从 Vi 出发的所有弧 ——O (n)<br>\n 第二步删除所有指向 Vi 的弧 ——O (e)<br>\n 综上合,时间复杂度为 O (n+e)</p>\n</blockquote>\n</li>\n</ol>\n",
"tags": [
"DS",
"数据结构"
]
},
{
"id": "https://735690757.github.io/PoliticalKnowledge/politicalNote/",
"url": "https://735690757.github.io/PoliticalKnowledge/politicalNote/",
"title": "政治知识点速记(持续更新)",
"date_published": "2024-10-25T03:00:00.000Z",
"content_html": "<h1 id=\"领航\"><a class=\"markdownIt-Anchor\" href=\"#领航\">#</a> 领航</h1>\n<div class=\"note primary no-icon\">\n<p><strong>部分口诀来自李丽双老师</strong></p>\n<p><strong>主要内容来自《肖秀荣 1000 题》、《精讲精炼》、《30 天 70 分》的答案解析</strong></p>\n<p><strong>以及其他同学们的笔记</strong></p>\n<p><strong>版权问题请联系作者 QQ:735690757</strong></p>\n</div>\n<h1 id=\"史纲\"><a class=\"markdownIt-Anchor\" href=\"#史纲\">#</a> 史纲</h1>\n<h1 id=\"马原理\"><a class=\"markdownIt-Anchor\" href=\"#马原理\">#</a> 马原理</h1>\n<h1 id=\"习思想\"><a class=\"markdownIt-Anchor\" href=\"#习思想\">#</a> 习思想</h1>\n<h2 id=\"琐碎\"><a class=\"markdownIt-Anchor\" href=\"#琐碎\">#</a> 琐碎</h2>\n<p>在习近平新时代中国特色社会主义思想的指导下,中国共产党团结带领中国人民,自信自强、守正创新,统揽伟大斗争、伟大工程、伟大事业、伟大梦想,<strong>创造了新时代中国特色社会主义的 伟大成就,为实现中华民族伟大复兴提供了<mark>更为完善的制度保证、更为坚实的物质基础、更为主动的精神力量</mark></strong>。</p>\n<h2 id=\"六个坚持\"><a class=\"markdownIt-Anchor\" href=\"#六个坚持\">#</a> 六个坚持</h2>\n<p>“六个必须坚持”: 必须坚持<mark>人民至上</mark>、必须坚持<mark>自信自立</mark>、必须坚持<mark>守正创新</mark>、必须坚持<mark>问题导向</mark>、必须坚持<mark>系统观念</mark>、必须坚持<mark>胸怀天下</mark>。</p>\n<div class=\"note primary\">\n<p>人心正道系天下</p>\n</div>\n<h2 id=\"党的根本宗旨\"><a class=\"markdownIt-Anchor\" href=\"#党的根本宗旨\">#</a> 党的根本宗旨</h2>\n<p>党的根本宗旨是全心全意为<mark>人民服务</mark></p>\n<h2 id=\"实现途径-行动指南-根本保障-精神力量\"><a class=\"markdownIt-Anchor\" href=\"#实现途径-行动指南-根本保障-精神力量\">#</a> 实现途径、行动指南、根本保障、精神力量</h2>\n<p>改革开放以来我们取得一切成绩和进步的根本原因,归结起来就是;开辟了中国特色社会主义道路,形成了中国特色社会主义理论体系,确立了中国特色社会主义制度,发展了中国特色社会主义文化。其中,道路是<strong>实现途径</strong>,理论体系是<strong>行动指南</strong>,制度是<strong>根本保障</strong>,文化是<strong>精神力量</strong>,四者统一于中国特色社会主义伟大实践。</p>\n<h2 id=\"四个自信理论支撑和根本依据\"><a class=\"markdownIt-Anchor\" href=\"#四个自信理论支撑和根本依据\">#</a> 四个自信理论支撑和根本依据</h2>\n<p><strong>马克思主义深刻揭示了社会主义必然代替资本主义的客观规律</strong>,这是我们坚定 “四个自信” 的<strong>理论支撑</strong>和<strong>根本依据</strong>。</p>\n<h2 id=\"四个自信的来源\"><a class=\"markdownIt-Anchor\" href=\"#四个自信的来源\">#</a> 四个自信的来源</h2>\n<p>中国特色社会主义道路自信、理论自信、制度自信、文化自信,来源于<mark>实践</mark>、来源于<mark>人民</mark>、来源于<mark>真理</mark>。</p>\n<h2 id=\"四个全面处于主导地位的是\"><a class=\"markdownIt-Anchor\" href=\"#四个全面处于主导地位的是\">#</a> 四个全面处于主导地位的是</h2>\n<p>“四个全面” 战略布局既有战略目标又有战略举措,每个 “全面” 之间具有紧密的内在逻辑是一个整体战略部署的有序展开。<mark>全面建设社会主义现代化国家是战略目标</mark>,在 “四个全面” 中<mark>居于引领地位</mark>;全面深化改革、全面依法治国、全面从严治党是三大战略举措,为全面建设社会主义现代化国家提供重要保障。</p>\n<h2 id=\"党的基本路线\"><a class=\"markdownIt-Anchor\" href=\"#党的基本路线\">#</a> 党的基本路线</h2>\n<p><strong>党的基本路线是<mark>国家的生命线</mark>、<mark>人民的幸福线</mark>。</strong></p>\n<h2 id=\"科学社会主义的主张\"><a class=\"markdownIt-Anchor\" href=\"#科学社会主义的主张\">#</a> 科学社会主义的主张</h2>\n<p>科学社会主义的主张受到中国人民热烈欢迎,并最终扎根中国大地、开花结果,是因为:第一,它<mark>回答了近代以来中华民族面临的历史性课题</mark> (求得民族独立和人民解放;实现国家富强和人民幸福)、<mark>指明了实现中华民族伟大复兴的正确道路</mark> (中国特色社会主义是实现中华民族复兴的正确道路); 第二,<mark>它同我国传承了几千年的优秀历史文化和广大人民日用而不觉的价值观念具有高度的契合性</mark></p>\n<h2 id=\"百年奋斗目标-不是顺序的而是交错的100年\"><a class=\"markdownIt-Anchor\" href=\"#百年奋斗目标-不是顺序的而是交错的100年\">#</a> 百年奋斗目标 - 不是顺序的而是交错的 100 年</h2>\n<p>第一个一百年(共产党成立 100 周年),是到中国共产党成立 100 年时全面建成小康社会(1921-2021)</p>\n<p>第二个一百年(新中国成立 100 周年),是到新中国成立 100 年时建成富强民主文明和谐美丽的社会主义现代化强国(1949-2049)</p>\n<h2 id=\"新形势下做好新闻舆论工作的关键\"><a class=\"markdownIt-Anchor\" href=\"#新形势下做好新闻舆论工作的关键\">#</a> 新形势下做好新闻舆论工作的关键</h2>\n<p>互联网是意识形态工作的主阵地、主战场、最前沿,<strong>管好用好互联网</strong>是新形势下做好新闻舆论工作的关键。习近平指出:“过不了互联网这一关,就过不了长期执政这一关。</p>\n<h2 id=\"文化是\"><a class=\"markdownIt-Anchor\" href=\"#文化是\">#</a> 文化是…</h2>\n<p>面建成社会主义现代化强国必然要求建设社会主义文化强国。统筹推进 “五位一体” 总体布局、协调推进 “四个全面” 战略布局,文化是<strong>重要内容</strong>;推动高质量发展,文化是<strong>重要支点</strong>;满足人民日益增长的美好生活需要,文化是<strong>重要因素</strong>;战胜前进道路上各种风险挑战,文化是<strong>重要力量源泉</strong>。只有推动文化繁荣兴盛,才能为推进中国式现代化建设、实现第二个百年奋斗目标提供思想保证、舆论支持、精神动力和文化条件。</p>\n<h2 id=\"中国共产党的精神之源\"><a class=\"markdownIt-Anchor\" href=\"#中国共产党的精神之源\">#</a> 中国共产党的精神之源</h2>\n<p><mark>伟大建党精神是中国共产党的精神之源</mark></p>\n<h2 id=\"关乎旗帜-关乎道路-关乎国家政治安全决定文化前进方向和发展道路\"><a class=\"markdownIt-Anchor\" href=\"#关乎旗帜-关乎道路-关乎国家政治安全决定文化前进方向和发展道路\">#</a> 关乎旗帜、关乎道路、关乎国家政治安全,决定文化前进方向和发展道路</h2>\n<p><ins>意识形态</ins>关乎旗帜、关乎道路、关乎国家政治安全,决定文化前进方向和发展道路。</p>\n<h2 id=\"坚持百花齐放-百家争鸣双百\"><a class=\"markdownIt-Anchor\" href=\"#坚持百花齐放-百家争鸣双百\">#</a> 坚持百花齐放、百家争鸣 (“双百”)</h2>\n<p>坚持百花齐放、百家争鸣 (“双百”) 是<mark>繁荣发展社会主义文化</mark>的重要方针。</p>\n<h2 id=\"坚持为人民服务-为社会主义服务二为\"><a class=\"markdownIt-Anchor\" href=\"#坚持为人民服务-为社会主义服务二为\">#</a> 坚持为人民服务、为社会主义服务 (“二为”)</h2>\n<p>坚持为人民服务、为社会主义服务 (“二为”) 的根本方向,是<mark>决定社会主义文化事业前途命运</mark>的关键。</p>\n<h2 id=\"区别于其他国家和民族的根本特征\"><a class=\"markdownIt-Anchor\" href=\"#区别于其他国家和民族的根本特征\">#</a> 区别于其他国家和民族的根本特征</h2>\n<p><strong>中华民族创造的优秀传统文化</strong>是民族的根脉,根植在中国人内心,形成了中国人看待世界、看待社会、看待人生的独特价值体系、文化内涵和精神品质,这是我们区别于其他国家和民族的<strong>根本特征</strong>。</p>\n<h2 id=\"文化的生命所在-本质特征\"><a class=\"markdownIt-Anchor\" href=\"#文化的生命所在-本质特征\">#</a> 文化的生命所在、本质特征</h2>\n<p><ins>创新创造</ins>是文化的生命所在,是文化的本质特征。因此</p>\n<h2 id=\"共同富裕的基础性制度\"><a class=\"markdownIt-Anchor\" href=\"#共同富裕的基础性制度\">#</a> 共同富裕的基础性制度</h2>\n<p>分配制度</p>\n<h2 id=\"初次分配\"><a class=\"markdownIt-Anchor\" href=\"#初次分配\">#</a> 初次分配</h2>\n<p>第一次分配的主体是市场参与的各要素主体。</p>\n<div class=\"note primary\">\n<p>初次分配,即初次收入分配。在<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTclQTQlQkUlRTQlQkMlOUElRTUlODglODYlRTklODUlOEQvMTI3NTQ5MzI/ZnJvbU1vZHVsZT1sZW1tYV9pbmxpbms=\">社会分配</span>中,初次分配注重效率,是按贡献分配。该贡献包括对创造利润有益的各种因素,如资金、技术、管理、<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTclOTQlOUYlRTQlQkElQTclRTglQjUlODQlRTYlOTYlOTkvMjUyMjU4MD9mcm9tTW9kdWxlPWxlbW1hX2lubGluaw==\">生产资料</span>、劳动力、信息、市场、营销等。谁能利用这些要素作出贡献,就能分到一杯羹。这样群策群力,效率便得以提高。</p>\n<p><span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTQlQjglODklRTYlQUMlQTElRTUlODglODYlRTklODUlOEQ=\">参考</span></p>\n</div>\n<h2 id=\"再分配\"><a class=\"markdownIt-Anchor\" href=\"#再分配\">#</a> 再分配</h2>\n<p>第二次分配的主体是政府。</p>\n<div class=\"note primary\">\n<p>再分配(二次分配)是指政府根据<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTYlQjMlOTUlRTUlQkUlOEIlRTYlQjMlOTUlRTglQTclODQvMzQ2ODczOD9mcm9tTW9kdWxlPWxlbW1hX2lubGluaw==\">法律法规</span>,在初次分配的基础上通过征收税收和政府<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTklOUQlOUUlRTclQTglOEUlRTYlOTQlQjYlRTUlODUlQTUvNDE1Mzg1Mz9mcm9tTW9kdWxlPWxlbW1hX2lubGluaw==\">非税收入</span>,在各收入主体之间以现金或实物进行的收入再次分配过程。与初次分配不同,再分配中起主导作用的是政府,强调公平的原则,具有通过<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTUlOUIlQkQlRTUlQUUlQjYlRTYlOUQlODMlRTUlOEElOUIvNDY1NTk1MD9mcm9tTW9kdWxlPWxlbW1hX2lubGluaw==\">国家权力</span>强制进行的特征。除了公平的目标外,再分配也通过教育、健康等<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTUlOUYlQkElRTYlOUMlQUMlRTUlODUlQUMlRTUlODUlQjElRTYlOUMlOEQlRTUlOEElQTEvMTA3MzY1NDg/ZnJvbU1vZHVsZT1sZW1tYV9pbmxpbms=\">基本公共服务</span>的提供,创造<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTYlOUMlQkElRTQlQkMlOUElRTUlQjklQjMlRTclQUQlODkvMTA4NDc2P2Zyb21Nb2R1bGU9bGVtbWFfaW5saW5r\">机会平等</span>的养教环境,以提升社会经济发展的<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTUlOEYlQUYlRTYlOEMlODElRTclQkIlQUQlRTYlODAlQTcvMjY1MDY2OT9mcm9tTW9kdWxlPWxlbW1hX2lubGluaw==\">可持续性</span>。</p>\n<p><span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTQlQjglODklRTYlQUMlQTElRTUlODglODYlRTklODUlOEQ=\">参考</span></p>\n</div>\n<h2 id=\"三次分配\"><a class=\"markdownIt-Anchor\" href=\"#三次分配\">#</a> 三次分配</h2>\n<p>而第三次分配的主体是民间社会力量,包括企业、社会组织和个人等。</p>\n<div class=\"note primary\">\n<p>三次分配有别于前两者,主要是企业、<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTclQTQlQkUlRTQlQkMlOUElRTclQkIlODQlRTclQkIlODcvMzMxOTc3OD9mcm9tTW9kdWxlPWxlbW1hX2lubGluaw==\">社会组织</span>、家族、家庭和个人等基于<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTglODclQUElRTYlODQlQkYlRTUlOEUlOUYlRTUlODglOTkvOTM2NTk1MD9mcm9tTW9kdWxlPWxlbW1hX2lubGluaw==\">自愿原则</span>和<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTklODElOTMlRTUlQkUlQjclRTUlODclODYlRTUlODglOTkvMjE3NzcwOT9mcm9tTW9kdWxlPWxlbW1hX2lubGluaw==\">道德准则</span>,以募集、捐赠、资助、义工等慈善、公益方式对所属资源和财富进行分配。社会组织和<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTclQTQlQkUlRTQlQkMlOUElRTUlOEElOUIlRTklODclOEYvODk4ODcxNT9mcm9tTW9kdWxlPWxlbW1hX2lubGluaw==\">社会力量</span>是三次分配的<span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTQlQjglQUQlRTUlOUQlOUElRTUlOEElOUIlRTklODclOEYvODcyNDg4Nz9mcm9tTW9kdWxlPWxlbW1hX2lubGluaw==\">中坚力量</span> 。</p>\n<p><span class=\"exturl\" data-url=\"aHR0cHM6Ly9iYWlrZS5iYWlkdS5jb20vaXRlbS8lRTQlQjglODklRTYlQUMlQTElRTUlODglODYlRTklODUlOEQ=\">参考</span></p>\n</div>\n<h2 id=\"三次分配的变化\"><a class=\"markdownIt-Anchor\" href=\"#三次分配的变化\">#</a> 三次分配的变化</h2>\n<p>市场👉政府👉社会</p>\n<h2 id=\"军民融合发展\"><a class=\"markdownIt-Anchor\" href=\"#军民融合发展\">#</a> 军民融合发展</h2>\n<p>习近平强军思想明确<strong>军民融合发展是兴国之举、强军之策</strong>;明确党对人民军队的绝对领导是人民军队建军之本、强军之魂;明确依法治军是我们党建军治军基本方式;明确作风优良是我军鲜明特色和政治优势。</p>\n<h2 id=\"政治建军\"><a class=\"markdownIt-Anchor\" href=\"#政治建军\">#</a> 政治建军</h2>\n<p>政治建军是人民军队的立军之本,抓军队建设首先要从政治上看。</p>\n<h2 id=\"依法治军\"><a class=\"markdownIt-Anchor\" href=\"#依法治军\">#</a> 依法治军</h2>\n<p>依法治军是我们党建军治军基本方式。</p>\n<h2 id=\"一流军队要求一流科技\"><a class=\"markdownIt-Anchor\" href=\"#一流军队要求一流科技\">#</a> 一流军队要求一流科技</h2>\n<p>一流军队要求一流科技,必须全面实施科技强军战略。</p>\n<p>科技是核心战斗力,是军事发展中最活跃、最具革命性的因素。</p>\n<h2 id=\"坚持党对人民军队的绝对领导\"><a class=\"markdownIt-Anchor\" href=\"#坚持党对人民军队的绝对领导\">#</a> 坚持党对人民军队的绝对领导</h2>\n<p><mark>军委主席负责制</mark>是坚持党对人民军队绝对领导的<mark>根本制度和根本实现形式</mark>,在党领导军队的一整套制度体系中处于最高层次,居于统领地位。</p>\n<h2 id=\"听党指挥首要-核心\"><a class=\"markdownIt-Anchor\" href=\"#听党指挥首要-核心\">#</a> 听党指挥 —— 首要、核心</h2>\n<p>听党指挥是<strong>灵魂</strong>,决定军队建设的<strong>政治方向</strong>;能打胜仗是<strong>核心</strong>,反映军队的根本职能和军队建设的<strong>根本指向</strong>。</p>\n<h2 id=\"作风优良保证-性质-宗旨-本质\"><a class=\"markdownIt-Anchor\" href=\"#作风优良保证-性质-宗旨-本质\">#</a> 作风优良 —— 保证、性质、宗旨、本质</h2>\n<p>作风优良是<strong>保证</strong>,关系军队的性质、宗旨、本色,是人民军队的<strong>鲜明特色和政治优势</strong>,也是人民军队战无不胜、攻无不克的<strong>重要保证</strong>。</p>\n<h2 id=\"作风优良核心\"><a class=\"markdownIt-Anchor\" href=\"#作风优良核心\">#</a> 作风优良 —— 核心</h2>\n<h2 id=\"关键一招\"><a class=\"markdownIt-Anchor\" href=\"#关键一招\">#</a> 关键一招</h2>\n<p>改革是决定人民军队发展壮大、制胜未来的关键一招。</p>\n<h2 id=\"四个战略支撑\"><a class=\"markdownIt-Anchor\" href=\"#四个战略支撑\">#</a> 四个战略支撑</h2>\n<p>我军新时代使命任务的四个战略支撑是:</p>\n<ol>\n<li>\n<p>为巩固<ins>中国共产党领导</ins>和<ins>社会主义制度</ins>提供战略支撑:确保党的领导和社会主义制度的安全和稳定。</p>\n</li>\n<li>\n<p>为<ins>捍卫国家主权、统一、领土完整</ins>提供战略支撑:维护国家的领土完整和主权不受侵犯。</p>\n</li>\n<li>\n<p>为<ins>维护国家海外利益</ins>提供战略支撑:保护国家在海外的利益和公民的安全。</p>\n</li>\n<li>\n<p>为<ins>促进世界和平与发展</ins>提供战略支撑:积极参与国际事务,推动世界和平与发展。</p>\n</li>\n</ol>\n<h2 id=\"一国两制\"><a class=\"markdownIt-Anchor\" href=\"#一国两制\">#</a> 一国两制</h2>\n<p>“一国两制” 的<mark>根本宗旨</mark>是<ins>维护国家主权、安全、发展利益,保持香港、澳门长期繁荣稳定</ins></p>\n<p><ins>维护国家</ins>安全是 “一国两制” 的<mark>核心要义</mark><br>\n<ins>维护国家主权、安全、发展利益</ins>是 “一国两制” 方针的<mark>最高原则</mark>,在这个前提下,香港、澳门保持原有的资本主义制度长期不变,享有高度自治权。</p>\n<p><ins>坚持 “爱国者治港”“爱国者治澳” 原则</ins>是事关国家主权、安全、发展利益,事关香港、澳门长期繁荣稳定的<mark>根本原则</mark>,是<ins>保证香港、澳门长治久安</ins>的<mark>必然要求</mark></p>\n<h2 id=\"全面贯彻新时代党解决台湾问题的总体方略\"><a class=\"markdownIt-Anchor\" href=\"#全面贯彻新时代党解决台湾问题的总体方略\">#</a> 全面贯彻新时代党解决台湾问题的总体方略</h2>\n<ol>\n<li><mark>根本保证</mark>坚持党中央对对台工作的集中统一领导</li>\n<li><mark>历史方位</mark>在中华民族伟大复兴进程中推进祖国统一</li>\n<li><mark>战略思路</mark>在祖国大陆发展进步基础上解决台湾问题</li>\n<li><mark>大政方针</mark> “和平统一、一国两制”</li>\n<li><mark>政治基础</mark>一个中国原则和 “九二共识”</li>\n<li><mark>实践途径</mark>推动两岸关系和平发展、融合发展</li>\n<li><mark>根本动力</mark>团结台湾同胞、争取台湾民心</li>\n<li><mark>必然要求</mark>粉碎 “台独” 分裂图谋</li>\n<li><mark>外部条件</mark>反对外部势力干涉</li>\n<li><mark>战略支撑</mark>决不承诺放弃使用武力</li>\n</ol>\n<h2 id=\"外交工作主线\"><a class=\"markdownIt-Anchor\" href=\"#外交工作主线\">#</a> 外交工作主线</h2>\n<p>服务民族复兴,促进人类进步</p>\n<h2 id=\"经济建设主线\"><a class=\"markdownIt-Anchor\" href=\"#经济建设主线\">#</a> 经济建设主线</h2>\n<p>供给侧结构性改革</p>\n<h2 id=\"全面深化改革开放主线\"><a class=\"markdownIt-Anchor\" href=\"#全面深化改革开放主线\">#</a> 全面深化改革开放主线</h2>\n<p>制度建设</p>\n<h2 id=\"一带一路\"><a class=\"markdownIt-Anchor\" href=\"#一带一路\">#</a> 一带一路</h2>\n<p>互联互通 —————————— 主线<br>\n共商共建共享 ———————— 原则<br>\n坚持开放、绿色、廉洁 ———— 理念<br>\n高标准、可持续、惠民生 ——— 目标</p>\n<h2 id=\"党建\"><a class=\"markdownIt-Anchor\" href=\"#党建\">#</a> 党建</h2>\n<p>加强党的长期执政能力建设,先进性和纯洁性建设</p>\n<h2 id=\"构建新型国际关系要秉持原则\"><a class=\"markdownIt-Anchor\" href=\"#构建新型国际关系要秉持原则\">#</a> 构建新型国际关系要秉持原则</h2>\n<ol>\n<li>相互尊重</li>\n<li>公平正义</li>\n<li>合作共赢原则</li>\n</ol>\n<p><ins>没有和平共处</ins></p>\n<h2 id=\"区分新型国际关系和大国关系\"><a class=\"markdownIt-Anchor\" href=\"#区分新型国际关系和大国关系\">#</a> 区分新型国际关系和大国关系</h2>\n<p>国际关系不用和平,大国关系不用共赢。</p>\n<h2 id=\"新型国际关系\"><a class=\"markdownIt-Anchor\" href=\"#新型国际关系\">#</a> 新型国际关系</h2>\n<p>尊重 — 合作 — 公平</p>\n<h2 id=\"新型国际关系又分为不同的具体要求\"><a class=\"markdownIt-Anchor\" href=\"#新型国际关系又分为不同的具体要求\">#</a> 新型国际关系又分为不同的具体要求</h2>\n<p>a、【大国关系格局】—— 和平共处、总体稳定、均衡发展<br>\n b、周边外交方针<br>\n c、周边外交理念(外交全局的首要位置)<br>\nd、发展中国家 —— 真实亲诚<br>\n e、新型政党关系 —— 求同存异、相互尊重、互学互鉴</p>\n<h2 id=\"党的政治建设首要任务\"><a class=\"markdownIt-Anchor\" href=\"#党的政治建设首要任务\">#</a> 党的政治建设首要任务</h2>\n<p>保证全党服从党中央,维护党中央权威和集中统一领导</p>\n<h1 id=\"毛中特\"><a class=\"markdownIt-Anchor\" href=\"#毛中特\">#</a> 毛中特</h1>\n<h2 id=\"琐碎-2\"><a class=\"markdownIt-Anchor\" href=\"#琐碎-2\">#</a> 琐碎</h2>\n<p><mark>“工农武装割据” 和农村包围城市、武装夺取政权</mark>的思想是<strong>毛泽东在<mark>土地革命</mark>战争时期</strong>提出的</p>\n<p><mark>实事求是</mark>,就是一切从实际出发,理论联系实际,坚持在实践中检验真理和发展真理,<mark>实事求是</mark>是<mark> A. 中国共产党的思想路线</mark>,<mark>B. 中国共产党人认识世界、改造世界的根本要求</mark>,<mark>C. 中国共产党的基本思想方法、工作方法、领导方法</mark>,<mark>D. 马克思主义的根本观点</mark></p>\n<div class=\"note primary\">\n<p><strong><mark>群众路线</mark>是党的<mark>生命线</mark>和<mark>根本工作路线</mark></strong></p>\n</div>\n<h2 id=\"南方谈话的内容\"><a class=\"markdownIt-Anchor\" href=\"#南方谈话的内容\">#</a> 南方谈话的内容</h2>\n<ol>\n<li>计划和市场都是经济手段;</li>\n<li>阐明了社会主义本质;</li>\n<li>提出了 “发展才是硬道理” 的重要论断</li>\n<li>提出判断改革开放和各项工作成败得失的 “三个有利于” 标准;</li>\n<li>强调加强党的建设;</li>\n<li>关于社会主义初级阶段的长期性和前途</li>\n</ol>\n<h2 id=\"速记口诀一二三四\"><a class=\"markdownIt-Anchor\" href=\"#速记口诀一二三四\">#</a> 速记口诀一二三四</h2>\n<p>一大立党,二大立纲,三大对国共合作的方针和办法做了正式决定,即 “党内合作”,四大提出无产阶级领导校和工农同盟军思想,五大批评陈独秀右倾错误,六大提出中国革命的性质是资产阶级民主革命,七大将毛理论命名为毛思想,并将其作为党的指导思想写入党章,八大提出主要矛盾,十二大提出建设中国特色社会主义社会,十三大系统地论述了关于社会主义初级阶段的理论,十四大概括了中国特色社会主义理论的主要内容,系统释了这一理论的历史地位和指导意义,十五大邓理论被确立为中国共产党的指导思想,并写入了党章。</p>\n<ol>\n<li>一党</li>\n<li>二纲</li>\n<li>三合作</li>\n<li>四权</li>\n<li>五批</li>\n<li>六性</li>\n<li>七入</li>\n<li>八矛</li>\n<li>十二大建中特</li>\n<li>十三大论阶段 (邓小平轮廓)</li>\n<li>十四大系阐释</li>\n<li>十五大邓入党章</li>\n<li>十八大进入新时代</li>\n</ol>\n<p>毛思想 -> 七大(毛七七)</p>\n<p>邓理论 -> 十五大</p>\n<p>三个代表 -> 十六大</p>\n<p>科学发展观 -> 十七大</p>\n<p>习思想 -> 十九大</p>\n<h2 id=\"一个神奇的口诀\"><a class=\"markdownIt-Anchor\" href=\"#一个神奇的口诀\">#</a> 一个神奇的口诀</h2>\n<p><mark>三线五纲,四体六康</mark></p>\n<h2 id=\"十三大\"><a class=\"markdownIt-Anchor\" href=\"#十三大\">#</a> 十三大</h2>\n<p>党的十一届三中全会的胜利召开,<mark>结束了粉碎 “四人帮” 后党</mark>和国家工作在徘徊中前进的局面,标志着中国共产党<mark>重新确立了马克思主义的思想路线、政治路线和组织路线</mark>,开启了我国<mark>改革开放和社会主义现代化建设历史新时期</mark>,实现了历史性的伟大转折。</p>\n<h2 id=\"十八大\"><a class=\"markdownIt-Anchor\" href=\"#十八大\">#</a> 十八大</h2>\n<p>中共十八大的召开,标志着中国已经进入全面建成<mark>小康社会的决定性阶段</mark>,<mark>开启了中国特 色社会主义新时代。</mark></p>\n<h2 id=\"毛泽东思想的地位\"><a class=\"markdownIt-Anchor\" href=\"#毛泽东思想的地位\">#</a> 毛泽东思想的地位</h2>\n<p>毛泽东思想是马克思主义中国化的<mark>第一次历史性飞跃</mark>的理论成 果;是<mark>中国革命和建设的科学指南</mark>;是<mark>党和人民的宝贵精神财富</mark>。</p>\n<h2 id=\"有关中心问题\"><a class=\"markdownIt-Anchor\" href=\"#有关中心问题\">#</a> 有关中心问题</h2>\n<p>①<mark>无产阶级的领导权是中国革命的中心问题</mark>。</p>\n<p>②在<mark>中国民主革命</mark>中,无产阶级领导权的中心问题是<mark>农民问题</mark>。</p>\n<p>③毛泽东在《国民革命与农民运动》中还提到 “农民问题乃国民革命的中心问题”。</p>\n<p>回答问题的时候要注意题干具体考查的角度。</p>\n<h2 id=\"革命的性质1948毛泽东指出\"><a class=\"markdownIt-Anchor\" href=\"#革命的性质1948毛泽东指出\">#</a> 革命的性质(1948 毛泽东指出…)</h2>\n<p>中国是一个封建经济占明显优势的半殖民地半封建社会,革命是为了终结这个半殖民地半封建的社会形态;中国革命的对象主要是<mark>帝国主义和封建主义势力</mark>;革命的性质是为了推翻这两个主要敌人的民族革命和民主革命</p>\n<h2 id=\"谁\"><a class=\"markdownIt-Anchor\" href=\"#谁\">#</a> 谁?</h2>\n<p>中国革命的中心问题、新民主主义苹命理论的<mark>核心问题</mark>:<mark>无产阶级的领导权问题</mark></p>\n<p>中国<mark>革命的实质</mark>:<mark>党领导下的农民革命</mark></p>\n<p>中国革命的最<mark>基本动力</mark>:<mark>无产阶级</mark>;</p>\n<p><mark>主力军</mark>:<mark>农民阶级</mark></p>\n<h2 id=\"打谁\"><a class=\"markdownIt-Anchor\" href=\"#打谁\">#</a> 打谁?</h2>\n<p>中国革命的<mark>首要问题</mark>:<mark>分清敌友</mark></p>\n<p>中国<mark>革命的对象</mark>:<mark>帝国主义 (首要对象)</mark>、<mark>封建主义</mark>和<mark>官僚资本主义</mark></p>\n<h2 id=\"为什么打\"><a class=\"markdownIt-Anchor\" href=\"#为什么打\">#</a> 为什么打?</h2>\n<p>中国革命的<mark>根本问题</mark>:<mark>国家政权问题</mark></p>\n<p>中国革命的<mark>基本问题</mark>:<mark>农民问题</mark></p>\n<h2 id=\"怎么打\"><a class=\"markdownIt-Anchor\" href=\"#怎么打\">#</a> 怎么打?</h2>\n<p>中国革命的主要内容:没收封建地主阶级的士地归农民所有</p>\n<h2 id=\"中国民主革命的基本内容\"><a class=\"markdownIt-Anchor\" href=\"#中国民主革命的基本内容\">#</a> 中国民主革命的基本内容</h2>\n<p>中国革命走农村包围城市、武装夺取政权的道路,必须处理好土地革命、武装斗争、农村革命根据地建设三者之间的关系。<strong><ins>土地革命</ins>是民主革命的<mark>基本内容</mark>;<ins>武装斗争</ins>是中国革命的<mark>主要形式</mark>,是农村革命根据地建设和土地革命的强<mark>有力保证</mark>;<ins>农村革命根据地</ins>是中国革命的<mark>战略阵地</mark>,是进行武装斗争和开展土地<mark>革命的依托</mark>。</strong></p>\n<h2 id=\"统一战线的经验\"><a class=\"markdownIt-Anchor\" href=\"#统一战线的经验\">#</a> 统一战线的经验</h2>\n<p>新民主主义革命时期,中国共产党领导的统一战线,先后经过了第一次国共合作的统一战线、工农民主统一战线、抗日民族统一战线、人民民主统一战线等几个时期,积累了丰富的经验。<strong>其中,最根本的经验就是正确处理好与<mark>资产阶级</mark>的关系</strong>当党能够正确处理与资产阶级建立统一战线或被迫分裂统一战线的问题时,党的发展和巩固就会前进;反之,党的发展和巩固就会后退。</p>\n<h2 id=\"建立统一战线的必要性\"><a class=\"markdownIt-Anchor\" href=\"#建立统一战线的必要性\">#</a> 建立统一战线的必要性</h2>\n<p>建立最广泛的统一战线,是由中国半殖民地半封建社会的阶级状况所决定的。毛泽东指出:“中国社会是一个两头小中间大的社会,无产阶级和地主大资产阶级都只占少数,最广大的人民是农民、城市小资产阶级以及其他的中间阶级。” 作为无产阶级先锋队的中国共产党所领导的革命力量,要战胜作为地主阶级和官僚资产阶级集中代表的国民党所领导的强大的反革命力量,<strong>就必须把农民、城市小资产阶级以及其他的中间阶级都团结在自己的周围,结成最广泛的统一战线。</strong></p>\n<h2 id=\"新民主主义革命时期的统一战线\"><a class=\"markdownIt-Anchor\" href=\"#新民主主义革命时期的统一战线\">#</a> 新民主主义革命时期的统一战线</h2>\n<p>党领导的统一战线,先后经过了<mark>第一次国共合作的统一战线</mark>、<mark>工农民主统一战线</mark>、<mark>抗日民族统一战线</mark>、<mark>人民民主统一战线</mark>等几个时期。</p>\n<p><mark>以国共合作为基础</mark>的是国民革命联合战线 (<mark>第一次国共合作的统一战线</mark>) 与<mark>抗日民族统一战线。</mark></p>\n<p><ins>国共就合作了 2 次,一次是推翻封建主义制度,一次是抗日合作</ins></p>\n<h2 id=\"新民主主义革命理论的基本纲领\"><a class=\"markdownIt-Anchor\" href=\"#新民主主义革命理论的基本纲领\">#</a> 新民主主义革命理论的基本纲领</h2>\n<p><strong>新民主主义文化是科学的</strong>,是<mark>反对一切封建思想和迷信思想</mark>主张实事求是、客观真理及理论和实践的一致性。对于封建时代创造的文化,应<mark>剔除其封建糟粕</mark>,<mark>吸收其民主性精华</mark>。同时,<strong>要尊重中国的历史,<mark>反对民族虚无主义</mark>,以历史唯物主义的态度对待古今中外文化,发展民族新文化,提高民族自信心。</strong></p>\n<h2 id=\"两步走\"><a class=\"markdownIt-Anchor\" href=\"#两步走\">#</a> ” 两步走 “</h2>\n<p>由于中国革命的反帝反封建的双重任务,决定了革命分两步走:第一步是先进行推翻三座大山的<mark>新民主主义革命</mark>,第二步是进行<mark>社会主义革命</mark>。</p>\n<h2 id=\"一次革命论和二次革命论都是错误的\"><a class=\"markdownIt-Anchor\" href=\"#一次革命论和二次革命论都是错误的\">#</a> “一次革命论” 和 “二次革命论” 都是错误的</h2>\n<p>“左” 倾<mark>教条主义的 “一次革命论”(如 “无间断” 革命论) 的错误</mark>在于,只看到了民主革命与社会主义革命的联系,而混淆了民主革命与社会主义革命的区别,在反帝反封建的同时,也反对民族资产阶级,否定了中国革命的阶段性。而<mark>右的 “二次革命论” 的错误</mark>在于,只看到了民主革命与社会主义革命的区别,而没有看到两个革命阶段的联系,放弃了党对民主革命的领导权。</p>\n<h2 id=\"两头小中间大的社会\"><a class=\"markdownIt-Anchor\" href=\"#两头小中间大的社会\">#</a> ” 两头小中间大” 的社会</h2>\n<p>毛泽东指出:“中国社会是一个两头小中间大的社会,<mark>无产阶级</mark>和<mark>地主大资产阶级</mark>都只占<ins>少数</ins>,最<ins>广大的人民</ins>是<mark>农民、城市小资产阶级以及其他的中间阶级</mark>。”</p>\n<h2 id=\"三件法宝\"><a class=\"markdownIt-Anchor\" href=\"#三件法宝\">#</a> 三件 “法宝”</h2>\n<p>统一战线、武装斗争、党的建设</p>\n<div class=\"note primary\">\n<p>战斗党</p>\n</div>\n<h2 id=\"战胜敌人的两个基本武器\"><a class=\"markdownIt-Anchor\" href=\"#战胜敌人的两个基本武器\">#</a> 战胜敌人的两个基本武器</h2>\n<p>统一战线、武装斗争</p>\n<div class=\"note primary\">\n<p>战斗</p>\n</div>\n<h2 id=\"中国革命道路\"><a class=\"markdownIt-Anchor\" href=\"#中国革命道路\">#</a> 中国革命道路</h2>\n<p>土地革命、武装斗争、农村革命根据地建设</p>\n<div class=\"note primary\">\n<p>土斗根</p>\n</div>\n<h2 id=\"活的灵魂\"><a class=\"markdownIt-Anchor\" href=\"#活的灵魂\">#</a> 活的灵魂</h2>\n<p>实事求是、群众路线、独立自主</p>\n<div class=\"note primary\">\n<p>实众独</p>\n</div>\n<h2 id=\"优良作风\"><a class=\"markdownIt-Anchor\" href=\"#优良作风\">#</a> 优良作风</h2>\n<p>理论联系实际、密切联系群众、批评与自我批评</p>\n<h2 id=\"新民主主义革命纲领最具特色一项\"><a class=\"markdownIt-Anchor\" href=\"#新民主主义革命纲领最具特色一项\">#</a> 新民主主义革命纲领最具特色一项</h2>\n<p><mark>保护民族工商业</mark>,是新民主主义经济纲领中极具特色的一项内容。在新民主主义条件下保护民族工商业,发展资本主义,是由中国落后的生产力和新民主主义革命的性质所决定的。新民主主义革命的对象是帝国主义、封建主义和官僚资本主义,而不是一般地消灭资本主义和资产阶级。</p>\n<h2 id=\"新民主主义革命胜利的历史意义\"><a class=\"markdownIt-Anchor\" href=\"#新民主主义革命胜利的历史意义\">#</a> 新民主主义革命胜利的历史意义</h2>\n<p><strong>新民主主义革命的伟大成就,为实现中华民族伟大复兴创造了根本社会条件。</strong></p>\n<h2 id=\"各个阶段中国社会的主要矛盾\"><a class=\"markdownIt-Anchor\" href=\"#各个阶段中国社会的主要矛盾\">#</a> 各个阶段中国社会的主要矛盾</h2>\n<p>1840—1949,中华民族与帝国主义的矛盾。</p>\n<p>1949—1952,与帝国主义、封建主义、国民党残余势力之间的矛盾。</p>\n<p>1952—1956,工人阶级和资产阶级之间的矛盾。(土改基本完成)</p>\n<p>1956—1978,人民对于建立先进的工业国的要求同落后的农业国的现实之间的矛盾,人民对于经济文化迅速发展的需要同当前经济文化不能满足人民需要的状况之间的矛盾。</p>\n<p>1978,人民日益增长的物质文化需要同落后的社会生产之间的矛盾。</p>\n<p>2018,人民日益增长的美好生活需要和不平衡不充分的发展之间的矛盾。</p>\n<h2 id=\"互助组-常年互助组-初级合作社-高级合作社\"><a class=\"markdownIt-Anchor\" href=\"#互助组-常年互助组-初级合作社-高级合作社\">#</a> 互助组、常年互助组、初级合作社、高级合作社</h2>\n<p><strong>互助组</strong> (<mark>包括临时互助组和常年互助组两种形式</mark>) 不涉及生产资料问题,只是在生产方面组织起来、互帮互助,是农业合作化的最初过渡形式,具有<ins>社会主义萌芽性质</ins>。<mark>初级农业生产合作社</mark>以土地入股和统一经营为特点,实行集体劳动,产品分配采取按劳分配和土地入股分红相结合,<ins>具有半社会主义性质</ins>。<mark>高级农业生产合作社</mark>实行生产资料农民集体所有,实行按劳分配,具有<ins>完全的社会主义性质</ins>。</p>\n<h2 id=\"民族资产阶级的两面性\"><a class=\"markdownIt-Anchor\" href=\"#民族资产阶级的两面性\">#</a> 民族资产阶级的两面性</h2>\n<p>既有<mark>剥削</mark>工人取得利润的一面,又有拥护中国共产党的领导、拥护宪法、愿意<mark>接受社会主义改造</mark>的一面</p>\n<h2 id=\"民族资产阶级与工人阶级的矛盾的两重性\"><a class=\"markdownIt-Anchor\" href=\"#民族资产阶级与工人阶级的矛盾的两重性\">#</a> 民族资产阶级与工人阶级的<strong>矛盾</strong>的两重性</h2>\n<p>既有剥削者与被剥削者的阶级利益相互<mark>对立的对抗性</mark>的一面,又有相互合作、具有相同利益的<mark>非对抗性</mark>的一面</p>\n<h2 id=\"资本主义工商业的社会主义改造经历了三个步骤\"><a class=\"markdownIt-Anchor\" href=\"#资本主义工商业的社会主义改造经历了三个步骤\">#</a> 资本主义工商业的社会主义改造经历了三个步骤</h2>\n<p>第一步 (<mark>初级形式的国家资本主义</mark>) 和第二步 (<mark>个别企业的公私合营</mark>) 的企业利润分配都是<ins>四马分肥</ins>。第三步 (<mark>全行业的公私合营</mark>) 在分配上实行<ins>定股定息</ins>。</p>\n<div class=\"note primary\">\n<p>第一步实行<mark>初级形式的国家资本主义</mark>。国家在私营工业中实行委托加工、计划订货、统购包销,这主要是<mark>同资本家在企业外部的合作</mark>。</p>\n<p>第二步实行<mark>个别企业的公私合营</mark>。这是社会主义成分同<mark>资本主义成分在企业内部的合作</mark>。</p>\n<p>第三步实行<mark>全行业的公私合营</mark>。全行业公私合营后,国家对合营企业进行清产核资、定股定息,委派人员负责企业的生产经营管理,统一调配企业的人、财、物,生产资料为国家所有。全行业公私合营后,企业的生产关系已经发生了根本的变化,基本上成为<mark>社会主义国营性质的企业</mark>。</p>\n</div>\n<h2 id=\"推进手工业合作化的方针\"><a class=\"markdownIt-Anchor\" href=\"#推进手工业合作化的方针\">#</a> 推进手工业合作化的方针</h2>\n<p>在推进手工业合作化的过程中,中国共产党采取的是<mark>积极领导、稳步前进的方针。</mark></p>\n<h2 id=\"推进农业社会主义改造的原则\"><a class=\"markdownIt-Anchor\" href=\"#推进农业社会主义改造的原则\">#</a> 推进农业社会主义改造的原则</h2>\n<p>这条道路遵循<mark>自愿互利、典型示范和国家帮助</mark>的原则,以互助合作的优越性吸引农民走互 助合作道路。</p>\n<div class=\"note primary\">\n<p>士力架</p>\n</div>\n<h2 id=\"资本主义工商业社会主义改造的方针\"><a class=\"markdownIt-Anchor\" href=\"#资本主义工商业社会主义改造的方针\">#</a> 资本主义工商业社会主义改造的方针</h2>\n<p>和平赎买</p>\n<h2 id=\"经济成分构成及阶级构成\"><a class=\"markdownIt-Anchor\" href=\"#经济成分构成及阶级构成\">#</a> 经济成分构成及阶级构成</h2>\n<p>三种主要的经济成分:社会主义经济、个体经济、资本主义经济</p>\n<p>阶级构成:工人、农民、民族资产阶级、其他小资产阶级</p>\n<p>其中,<ins>半社会主义性质的合作社经济是<mark>个体经济</mark>向<mark>社会主义集体经济</mark>过渡的形式</ins>,<ins>国家资本主义经济是<mark>私人资本主义经济</mark>向<mark>社会主义国营经济</mark>过渡的形式。</ins></p>\n<h2 id=\"萌芽性质-半社会主义性质-完全社会主义性质\"><a class=\"markdownIt-Anchor\" href=\"#萌芽性质-半社会主义性质-完全社会主义性质\">#</a> 萌芽性质、半社会主义性质、完全社会主义性质</h2>\n<p>社会主义萌芽:农业互助组,手工业供销小组,资本主义工商业初级国家资本主义经济</p>\n<p>半社会主义:农业初级生产合作社,手工业供销合作社,工商业个别企业公私合营</p>\n<p>完全社会主义:农业高级生产合作社,手工业生产合作社,工商业全行业公私合营</p>\n<div class=\"note primary\">\n<p>工商业:高级国家资本主义 = 个别企业公私合营 + 全行业公私合营</p>\n</div>\n<h2 id=\"1956年年底社会主义改造的基本完成\"><a class=\"markdownIt-Anchor\" href=\"#1956年年底社会主义改造的基本完成\">#</a> 1956 年年底社会主义改造的基本完成</h2>\n<ol>\n<li>标志着中国历史上长达数千年的阶级剥削制度的结束</li>\n<li>实现了由新民主主义向社会主义的转变</li>\n<li>标志着社会主义基本制度在我国确立</li>\n<li>标志着我国的社会主义初级阶段从此开始</li>\n</ol>\n<h2 id=\"两个结合和两次结合\"><a class=\"markdownIt-Anchor\" href=\"#两个结合和两次结合\">#</a> 两个结合和 “两次结合”</h2>\n<p>毛泽东的两次结合:马 + 革命、马 + 建设道路</p>\n<p>习近平的两个结合:马 + 中国国情、马 + 传统文化</p>\n<h2 id=\"论十大关系探索中国社会主义建设道路的良好开端\"><a class=\"markdownIt-Anchor\" href=\"#论十大关系探索中国社会主义建设道路的良好开端\">#</a> 《论十大关系》—— 探索中国社会主义建设道路的良好开端</h2>\n<p>毛泽东在 1956 年 4 月 25 日中央政治局扩大会议和 5 月 2 日最高国务会议上作《论十大关系》的报告。<strong>强调<ins>以苏为鉴、独立自主地探索适合中国情况的社会主义建设道路</ins>。其中,《论十大关系》中的第一大关系,即<ins>重工业和轻工业、农业的关系</ins>。</strong></p>\n<p>在《论十大关系》的报告中,初步总结了我国社会主义建设的经验,明确提出要以苏为鉴,独立自主地探索适合中国情况的社会主义建设道路。《<strong>论十大关系》标志着党探索中国社会主义建设道路的良好开端</strong>。</p>\n<div class=\"note primary\">\n<p>十全十美良好开端</p>\n</div>\n<h2 id=\"关于正确处理人民内部矛盾的问题\"><a class=\"markdownIt-Anchor\" href=\"#关于正确处理人民内部矛盾的问题\">#</a> 《关于正确处理人民内部矛盾的问题》</h2>\n<p>《关于正确处理人民内部矛盾的问题》一文,是一篇重要的马克思主义文献。它创造性地阐述了<ins>社会主义社会矛盾学说</ins>,<ins>是对科学社会主义理论的重要发展</ins>,<ins>对中国社会主义事业具有长远的指导意义</ins>。</p>\n<p>《关于正确处理人民内部矛盾的问题》指出,<strong>对于政治思想领域的人民内部矛盾,<mark>实行 “团结 — 批评 — 团结” 的方针</mark>,<mark>坚持说服教育、讨论的方法</mark>。</strong></p>\n<h2 id=\"中国特色社会主义理论体系形成发展的帽子题\"><a class=\"markdownIt-Anchor\" href=\"#中国特色社会主义理论体系形成发展的帽子题\">#</a> 中国特色社会主义理论体系形成发展的帽子题</h2>\n<p>中国特色社会主义理论体系形成发展的<ins>社会历史条件</ins>:【<mark>国际背景 + 历史条件 + 实践基础</mark>】</p>\n<p><mark>而如果光问<ins>历史条件</ins>就不一样,<ins>社会历史条件</ins>范围要大一些</mark></p>\n<div class=\"note primary\">\n<p>国际形势的深刻变化和世界发展新趋势 —— 国际背景;</p>\n<p>建设社会主义正反两方面经验和我国发展的历史方位 —— 历史条件;</p>\n<p>改革开放和社会主义现代化建设实践 —— 实践基础</p>\n</div>\n<h2 id=\"中国特色社会主义理论体系形成发展的历史条件\"><a class=\"markdownIt-Anchor\" href=\"#中国特色社会主义理论体系形成发展的历史条件\">#</a> 中国特色社会主义理论体系形成发展的历史条件</h2>\n<p>党的十一届三中全会以后,中国共产党人鲜明指出建设社会主义没有固定的模式,** 必须结合中国实际,在实践中不懈探索和回答什么是社会主义、怎样建设社会主义这一基本问题。** 正是在探索和回答这一首要的基本的理论问题的过程中,我们党开创了中国特色社会主义的伟大事业。</p>\n<h2 id=\"马克思主义中国化的第一次飞跃与第二次飞跃\"><a class=\"markdownIt-Anchor\" href=\"#马克思主义中国化的第一次飞跃与第二次飞跃\">#</a> 马克思主义中国化的第一次飞跃与第二次飞跃</h2>\n<p>== 马克思主义中国化的第一次飞跃,是党在探索中国革命道路的过程中完成的。== 在毛泽东思想的指导下,党领导人民走以农村包围城市的道路,取得了新民主主义革命的胜利;走具有中国特色的社会主义改造的道路,积极探索社会主义建设道路,取得社会主义革命和建设的伟大成就。</p>\n<p><mark>马克思主义中国化时代化的第二次飞跃是中国特色社会主义理论体系。</mark></p>\n<h2 id=\"毛泽东思想的精髓\"><a class=\"markdownIt-Anchor\" href=\"#毛泽东思想的精髓\">#</a> 毛泽东思想的精髓</h2>\n<p>实事求是</p>\n<h2 id=\"邓小平理论的精髓\"><a class=\"markdownIt-Anchor\" href=\"#邓小平理论的精髓\">#</a> 邓小平理论的精髓</h2>\n<p>解放思想,实事求是</p>\n<h2 id=\"十三大提出社会主义初级阶段基本路线\"><a class=\"markdownIt-Anchor\" href=\"#十三大提出社会主义初级阶段基本路线\">#</a> 十三大提出社会主义初级阶段基本路线</h2>\n<p>基本途径:一个中心,两个基本点(以经济建设为中心,坚持改革开放,坚持四项基本原则)</p>\n<p>跟本立足点:自力更生,艰苦创业</p>\n<p>领导力量和依靠力量:领导和团结各族人民</p>\n<p>奋斗目标:建设富强民主文明的社会主义现代化国家</p>\n<h2 id=\"几个帽子\"><a class=\"markdownIt-Anchor\" href=\"#几个帽子\">#</a> 几个帽子</h2>\n<p>改革 —— 是社会主义社会发展的直接动力;</p>\n<p>阶级斗争 —— 是阶级社会发展的直接动力;</p>\n<p>科技 —— 是第一生产力;</p>\n<p>科技革命–是社会发展的重要动力。</p>\n<p>解放生产力,发展生产力,是社会主义的根本任务。</p>\n<h2 id=\"三个有利于\"><a class=\"markdownIt-Anchor\" href=\"#三个有利于\">#</a> 三个有利于</h2>\n<ol>\n<li>是否有利于发展社会主义生产力</li>\n<li>是否有利于增强社会主义国家的综合国力</li>\n<li>是否有利于提高人民的生活水平</li>\n</ol>\n<div class=\"note primary\">\n<p>生国人</p>\n</div>\n<h2 id=\"正确认识和处理改革-发展-稳定的关系\"><a class=\"markdownIt-Anchor\" href=\"#正确认识和处理改革-发展-稳定的关系\">#</a> 正确认识和处理改革、发展、稳定的关系</h2>\n<p>改革是动力,发展是目的,稳定是前提。要把改革的力度、发展的速度和社会可承受的程度统一起来,<strong>把不断改善人民生活作为处理改革、发展、稳定关系的重要结合点</strong>,在社会稳定中推进改革发展,通过改革发展促进社会稳定。</p>\n<h2 id=\"三个代表重要思想的花边\"><a class=\"markdownIt-Anchor\" href=\"#三个代表重要思想的花边\">#</a> “三个代表” 重要思想的” 花边 “</h2>\n<p>“三个代表” 重要思想是在对<mark>冷战结束后国际局势科学判断的基础上形成的</mark>,是在科学判断党的<mark>历史方位和总结历史经验</mark>的基础上提出来的,是在建设<mark>中国特色社会主义伟大实践</mark>的基础上形成的。</p>\n<h2 id=\"三个代表重要思想\"><a class=\"markdownIt-Anchor\" href=\"#三个代表重要思想\">#</a> “三个代表” 重要思想</h2>\n<ol>\n<li>中国共产党始终代表中国先进生产力的<ins>发展要求</ins></li>\n<li>始终代表中国先进文化的<ins>前进方向</ins></li>\n<li>始终代表中国最广大人民的<ins>根本利益</ins></li>\n</ol>\n<h2 id=\"新民主主义革命时期-1921-1949\"><a class=\"markdownIt-Anchor\" href=\"#新民主主义革命时期-1921-1949\">#</a> 新民主主义革命时期 1921-1949</h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">子时期</th>\n<th style=\"text-align:center\">时间</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\"><strong>党的创立和大革命时期</strong></td>\n<td style=\"text-align:center\">1921-1927</td>\n</tr>\n<tr>\n<td style=\"text-align:center\"><strong>土地革命战争时期</strong></td>\n<td style=\"text-align:center\">1927-1937</td>\n</tr>\n<tr>\n<td style=\"text-align:center\"><strong>全民族抗日战争时期</strong></td>\n<td style=\"text-align:center\">1937-1945</td>\n</tr>\n<tr>\n<td style=\"text-align:center\"><strong>解放战争时期</strong></td>\n<td style=\"text-align:center\">1945-1949</td>\n</tr>\n</tbody>\n</table>\n<h2 id=\"新民主主义社会时期-1949-1956\"><a class=\"markdownIt-Anchor\" href=\"#新民主主义社会时期-1949-1956\">#</a> 新民主主义社会时期 1949-1956</h2>\n<h2 id=\"社会主义建设时期-1956-1978\"><a class=\"markdownIt-Anchor\" href=\"#社会主义建设时期-1956-1978\">#</a> 社会主义建设时期 1956-1978</h2>\n<h2 id=\"1978之后\"><a class=\"markdownIt-Anchor\" href=\"#1978之后\">#</a> 1978 之后</h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">大事件</th>\n<th style=\"text-align:center\">时间</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\">十一届三中全会提出改革开放</td>\n<td style=\"text-align:center\">1978</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">提出命题 “建设有中国特色的社会主义</td>\n<td style=\"text-align:center\">1982</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">苏联解体,冷战结束</td>\n<td style=\"text-align:center\">1991</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">南方谈话</td>\n<td style=\"text-align:center\">1992</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">中共十四大,确立社会主义市场经济体制的改革目标</td>\n<td style=\"text-align:center\">1992</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">邓小平理论提出</td>\n<td style=\"text-align:center\">1997</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">三个代表指导思想</td>\n<td style=\"text-align:center\">2002</td>\n</tr>\n</tbody>\n</table>\n<h2 id=\"科学发展观\"><a class=\"markdownIt-Anchor\" href=\"#科学发展观\">#</a> 科学发展观</h2>\n<p>第一要义:发展</p>\n<p>核心立场:以人为本</p>\n<p>基本要求:全面可持续发展</p>\n<p>根本方法:统筹兼顾</p>\n<p>保持先进性是党自身建设的根本任务和永恒课题</p>\n<h2 id=\"科学发展观的形成条件\"><a class=\"markdownIt-Anchor\" href=\"#科学发展观的形成条件\">#</a> 科学发展观的形成条件</h2>\n<ol>\n<li>是在深刻把握我国基本国情和新的阶段性特征的基础 上形成和发展的。</li>\n<li>是在深入总结改革开放以来实践经验的基础上形成和发展的。</li>\n<li>是在深刻分析国际形势及借鉴国外发展经验基础上形成和发展的。</li>\n</ol>\n<h2 id=\"领导人的思想精髓\"><a class=\"markdownIt-Anchor\" href=\"#领导人的思想精髓\">#</a> 领导人的思想精髓</h2>\n<p>毛泽东:实事求是<br>\n邓小平:解放思想,实事求是<br>\n江泽民:解放思想,实事求是,与时俱进<br>\n胡锦涛:解放思想,实事求是,与时俱进,求真务实</p>\n<h1 id=\"思修\"><a class=\"markdownIt-Anchor\" href=\"#思修\">#</a> 思修</h1>\n<h2 id=\"琐碎-3\"><a class=\"markdownIt-Anchor\" href=\"#琐碎-3\">#</a> 琐碎</h2>\n<p>中国特色社会主义建设实践是社会主义核心价值观的现实基础<br>\n先进性、人民性和真实性是社会主义核心价值观的道义力量</p>\n<h2 id=\"道德作用\"><a class=\"markdownIt-Anchor\" href=\"#道德作用\">#</a> 道德作用</h2>\n<p>认识功能 — 反映揭示(行为前)<br>\n规范功能 — 规范引导(行为中)<br>\n调节功能 — 指导纠正(行为后)</p>\n<h2 id=\"爱国主义\"><a class=\"markdownIt-Anchor\" href=\"#爱国主义\">#</a> 爱国主义</h2>\n<p>爱国主义是 道德要求 政治原则 法律规范 精神纽带</p>\n<p>以爱国主义为核心的民族精神,以改革创新为核心的时代精神</p>\n<h2 id=\"信念\"><a class=\"markdownIt-Anchor\" href=\"#信念\">#</a> 信念</h2>\n<p>执着性、支撑性、多样性</p>\n<h2 id=\"理想\"><a class=\"markdownIt-Anchor\" href=\"#理想\">#</a> 理想</h2>\n<p>超越性、实践性、时代性</p>\n<h2 id=\"价值观\"><a class=\"markdownIt-Anchor\" href=\"#价值观\">#</a> 价值观</h2>\n<p>先进性、人民性、真实性</p>\n<h2 id=\"区分创造精神梦想精神团结精神和奋斗精神\"><a class=\"markdownIt-Anchor\" href=\"#区分创造精神梦想精神团结精神和奋斗精神\">#</a> 区分创造精神,梦想精神,团结精神,和奋斗精神</h2>\n<p>神话就是梦想,发明一类就是创造,开垦治理河流之类的就是奋斗,剩下的那个就是团结</p>\n<h2 id=\"文化\"><a class=\"markdownIt-Anchor\" href=\"#文化\">#</a> 文化</h2>\n<p>文化是涵养民族心理、民族个性、民族精神的摇篮,而不是祖国大好河山</p>\n<h2 id=\"祖国河山\"><a class=\"markdownIt-Anchor\" href=\"#祖国河山\">#</a> 祖国河山</h2>\n<p>祖国的河山在人们的心中占据着<mark>至高无上</mark>的地位,祖国的山山水水<mark>滋养哺育着她的子子孙孙</mark>。“禾苗离土即死,国家无土难存”, 祖国的大好河山,不只是自然风光,更<mark>是主权、财富、民族发 展和进步</mark>的基本载体。因此,每一个爱国者都会把 “保我国土” “爱我家乡”、维护祖国领土的完整和统一,作为自己的神圣使命和义不容辞的责任。</p>\n<h2 id=\"中华传统美德的根本要求\"><a class=\"markdownIt-Anchor\" href=\"#中华传统美德的根本要求\">#</a> 中华传统美德的根本要求</h2>\n<p>中华传统美德的根本要求是公义胜私欲</p>\n<h2 id=\"道德的作用\"><a class=\"markdownIt-Anchor\" href=\"#道德的作用\">#</a> 道德的作用</h2>\n<ol>\n<li>道德为经济基础的形成、巩固和发展服务,是一种重要的精神力量。</li>\n<li>道德对其他社会意识形态的存在有着重大的影响</li>\n<li>道德通过调整人们之间的关系维护社会秩序和稳定</li>\n<li>道德是提高人的精神境界、促进人的自我完善,推动人的全面发展的内在动力</li>\n<li>在阶级社会中,道德是阶级斗争的重要工具</li>\n</ol>\n<h2 id=\"公共生活的四个特征\"><a class=\"markdownIt-Anchor\" href=\"#公共生活的四个特征\">#</a> 公共生活的四个特征</h2>\n<ol>\n<li>一是活动范围的<ins>广泛性</ins></li>\n<li>二是活动内容的<ins>开放性</ins></li>\n<li>三是交往对象的<ins>复杂性</ins></li>\n<li>四是活动方式的<ins>多样性</ins></li>\n</ol>\n<h2 id=\"全心全意为人民服务是贯穿中国革命道德的一根红线\"><a class=\"markdownIt-Anchor\" href=\"#全心全意为人民服务是贯穿中国革命道德的一根红线\">#</a> 全心全意为人民服务是贯穿中国革命道德的一根红线</h2>\n<ol>\n<li>是坚持历史唯物主义必然要求</li>\n<li>是中国共产党践行根本宗旨</li>\n<li>也是社会主义道德观集中体现</li>\n<li>是全体中国人民共同遵循道德要求</li>\n<li>是社会主义经济基础和人际关系的客观要求</li>\n<li>是社会主义市 场经济健康发展的要求</li>\n<li>是先进性要求和广泛性要求的统一</li>\n<li>为人民服务是社会主义道德的核心</li>\n<li>集体主义是社会主义道德的原则</li>\n</ol>\n<h2 id=\"法律的作用\"><a class=\"markdownIt-Anchor\" href=\"#法律的作用\">#</a> 法律的作用</h2>\n<ol>\n<li>普遍适用(遵守)</li>\n<li>优先适用</li>\n<li>不可违返(遵守 + 制裁)</li>\n</ol>\n<h1 id=\"时政2024年\"><a class=\"markdownIt-Anchor\" href=\"#时政2024年\">#</a> 时政(2024 年)</h1>\n<h2 id=\"二十届三中全会\"><a class=\"markdownIt-Anchor\" href=\"#二十届三中全会\">#</a> 二十届三中全会</h2>\n<ol>\n<li>通过了《中共中央关于进一步全面深化改革、推进中国式现代化的决定》(最重要成果)</li>\n<li>当前和今后一个时期是以中国式现代化全面推进强国建设、民族复兴伟业的关键时期</li>\n<li><mark>高水平社会主体市场经济体制</mark>是中国式现代化的<ins>重要保障</ins></li>\n<li><mark>教育、科技、人才</mark>是中国式现代化的<ins>基础性、战略性支撑</ins></li>\n<li><mark>城乡融合发展</mark>是中国式现代化<ins>的必然要求</ins></li>\n<li><mark>开放</mark>是中国式现代化的<ins>鲜明标识</ins></li>\n<li><mark>发展全过程人民民主</mark>是中国式现代化的<ins>本质要求</ins></li>\n<li><mark>法治</mark>是中国式现代化的<ins>重要保障</ins></li>\n<li>在<mark>发展中保障和改善民生</mark>是中国式现代化的<ins>重大任务</ins></li>\n<li><mark>国家安全</mark>是中国式现代化行稳致远的<ins>重要基础</ins></li>\n<li><mark>国防和军队现代化</mark>是中国式现代化的<ins>重要组成部分</ins></li>\n<li><mark>党的领导</mark>是进一步全面深化改革、推进中国式现代化的<ins>根本保证</ins></li>\n</ol>\n<h2 id=\"2024年中非合作论坛北京峰会\"><a class=\"markdownIt-Anchor\" href=\"#2024年中非合作论坛北京峰会\">#</a> 2024 年中非合作论坛北京峰会</h2>\n<p>2024 年中非合作论坛北京峰会的<mark>主题为 “携手推进现代化,共筑高水平中非命运共同体”。</mark></p>\n<p><ins>治国理政</ins>、<ins>工业化和农业现代化</ins>、<ins>和平安全</ins>、<ins>高质量共建 “一带一路” 分别是</ins>中非合作论坛北京峰会四场高级别会议的<ins>议题。</ins></p>\n<h2 id=\"培养社会主义法治思维\"><a class=\"markdownIt-Anchor\" href=\"#培养社会主义法治思维\">#</a> 培养社会主义法治思维</h2>\n<p>宪法保障、立法保障、行政保障和司法保障。</p>\n<p>宪法保障是权利保障的前提和基础,</p>\n<p>立法保障是权利保障的重要条件,</p>\n<p>行政保障是权利保障的关键环节,</p>\n<p>司法保障是公民权利保障的最后防线。</p>\n<h2 id=\"建设中国特色社会主义法治体系\"><a class=\"markdownIt-Anchor\" href=\"#建设中国特色社会主义法治体系\">#</a> 建设中国特色社会主义法治体系</h2>\n<p>建设中国特色社会主义法治体系,就是要形成完备的法律规范体系、高效的法治实施体系、严密的法治监督体系、有力的法治保障体系,形成完善的党内法规体系。</p>\n<p>形成完备的法律规范体系,是中国特色社会主义法治体系的前提,是法治国家、法治政府、法治社会的制度基础;</p>\n<p>建设高效的法治实施体系,是建设中国特色社会主义法治体系的重点;</p>\n<p>形成严密的法治监督体系,是宪法法律有效实施的重要保障;</p>\n<p>建设有力的法治保障体系,是全面依法治国的重要依托;</p>\n<p>形成完善的党内法规体系,是中国特色社会主义法治体系的本质要求和重要内容。</p>\n<h2 id=\"六个必须坚持\"><a class=\"markdownIt-Anchor\" href=\"#六个必须坚持\">#</a> 六个必须坚持</h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">坚持</th>\n<th style=\"text-align:center\">是…</th>\n<th>体现了</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\">人民至上</td>\n<td style=\"text-align:center\">根本价值立场</td>\n<td>唯物主义群众史观</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">自立自信</td>\n<td style=\"text-align:center\">内在精神特质</td>\n<td>客观规律性和主观能动性的有机结合</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">守正创新</td>\n<td style=\"text-align:center\">鲜明理论品格</td>\n<td>变与不变,继承与发展的内在联系</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">问题导向</td>\n<td style=\"text-align:center\">重要实践要求</td>\n<td>矛盾的普遍性与客观性</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">系统观念</td>\n<td style=\"text-align:center\">基本思想和工作方法</td>\n<td>辩证唯物主义普遍联系的原理</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">胸怀天下</td>\n<td style=\"text-align:center\">中国共产党人的境界格局</td>\n<td>马克思主义追求人类进步和解放的崇高理想</td>\n</tr>\n<tr>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<h2 id=\"新质生产力口诀\"><a class=\"markdownIt-Anchor\" href=\"#新质生产力口诀\">#</a> 新质生产力口诀</h2>\n<p>关谷悠悠业务劳累咳嗽,立志全心做点心。</p>\n<ol>\n<li>关键在于质优(关谷悠悠)</li>\n<li>重点任务是新产业(业务)</li>\n<li>内涵 —— 劳动者、劳动对象、劳动资料(劳累)</li>\n<li>核心要素 —— 科技创新(咳嗽)</li>\n<li>本质 —— 先进生产力(立志)</li>\n<li>核心标志 —— 全要素生产率(全心)</li>\n<li>显著特点 —— 创新(创新)</li>\n</ol>\n<h2 id=\"多民族国家\"><a class=\"markdownIt-Anchor\" href=\"#多民族国家\">#</a> 多民族国家…</h2>\n<p>血脉相融 —— 历史根基<br>\n信念相同 —— 内生动力<br>\n文化相通 —— 文化基因<br>\n经济相依 —— 强大力量</p>\n<h2 id=\"科技创新和产业创新深度融合\"><a class=\"markdownIt-Anchor\" href=\"#科技创新和产业创新深度融合\">#</a> 科技创新和产业创新深度融合</h2>\n<p>基础 —— 高质量科技供给<br>\n关键 —— 企业科技创新主体地位<br>\n途径 —— 促进科技成果转化应用</p>\n<h1 id=\"主观题解题\"><a class=\"markdownIt-Anchor\" href=\"#主观题解题\">#</a> 主观题解题</h1>\n<h2 id=\"问题分类\"><a class=\"markdownIt-Anchor\" href=\"#问题分类\">#</a> 问题分类</h2>\n<ol>\n<li>为什么</li>\n<li>是什么… 如何理解?</li>\n<li>意义是?</li>\n<li>怎么做?未来怎么做?</li>\n</ol>\n<p>四大类型 + 主语</p>\n<h2 id=\"万能三步走\"><a class=\"markdownIt-Anchor\" href=\"#万能三步走\">#</a> 万能三步走</h2>\n<p>观点【出发点】+ 落脚点 + 论据</p>\n<h2 id=\"中国声音关键词\"><a class=\"markdownIt-Anchor\" href=\"#中国声音关键词\">#</a> 中国声音关键词</h2>\n<p>携手共建人类命运共同体、和平、公道正义、共同发展、发展与安全、公正</p>\n<p>一切的核心是共同发展,构建人类命运共同体。</p>\n<p>和平共处五项原则发表 70 周年,引出中非合作论坛峰会,引出上海合作组织、引出国际友好大会、引出金砖国家领导人第十六次会晤、引出二十国集团领导人第十九次峰会。</p>\n<p>抓住主旋律:</p>\n<ol>\n<li>观点:世界和平发展、安全、公道正义、合作、多边主义</li>\n<li>落脚点:人类命运共同体、全人类共同价值</li>\n</ol>\n<h2 id=\"小小模板\"><a class=\"markdownIt-Anchor\" href=\"#小小模板\">#</a> 小小模板</h2>\n<h3 id=\"38时政第一问\"><a class=\"markdownIt-Anchor\" href=\"#38时政第一问\">#</a> 38 时政,第一问</h3>\n<pre><code>当前,世界百年变局加速推进,一些西方国家为维护自身霸权,大搞单边主义、保护主义,建立封闭排他的“小圈子”,危害世界和平与共同发展。\n①(主语【材料】金砖....)坚持开放包容、合作共赢的初心使命,顺应全球南方崛起大势。\n②(主语【材料】中非....)走到一起,顺应世界和平和发展发出和平之声,倡导互惠包容的经济全球化和世界多极化,坚守共同发展的大道。\n③(主语【材料】和平共处五项原则....)树立了历史标杆,为不同社会制度国家建立和发展关系提供正确指导,为发展中国家团结合汇聚强大合力,为推动国际秩序朝着更加公正合理的方向贡献了中国智慧。\n</code></pre>\n<h3 id=\"38时政第二问\"><a class=\"markdownIt-Anchor\" href=\"#38时政第二问\">#</a> 38 时政,第二问</h3>\n<pre><code>历史和现实告诉我们,各国必须共担维护和平责任,同走和平发展道路,要秉持公道正义的理念,展现开放包容的胸襟。\n①我们要建设“和平金砖”、“创新金砖”、“绿色金砖”、“公正金砖”,“人文金砖”。\n②我们要坚持和平的原则,夯实相互尊重的基础,实现和平安全的愿景,汇聚共筑繁荣的动力。\n③提出“坚持和平,实现共同安全” “重振发展,实现普遍繁荣” “共兴文明,实现多元和谐发展”三点主张。\n在世界变局乱局中开辟长治久安、共同繁荣的人间正道,奋力开创中国特色大国外交更有作为的新局面,为进一步全面深化改革、推进中国式现化、推为构建人类命运共同体作出新的贡献。\n</code></pre>\n<p>有金砖写一二,无金砖选二三</p>\n",
"tags": [
"political",
"政治"
]
},
{
"id": "https://735690757.github.io/Operate-system/OSPVCode/",
"url": "https://735690757.github.io/Operate-system/OSPVCode/",
"title": "操作系统PV代码题速记",
"date_published": "2024-09-24T12:41:00.000Z",
"content_html": "<h1 id=\"操作系统pv代码题速记\"><a class=\"markdownIt-Anchor\" href=\"#操作系统pv代码题速记\">#</a> 操作系统 PV 代码题速记</h1>\n<p>进程 P 向 m 个进程 Q1、Q2、Q3…Qm 发送消息,进程 P 发消息到缓冲区,只有所有的 Q 进程都接收到消息后,进程 P 才能继续向缓冲区放消息,请写出 PV 操作逻辑。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore mutex<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> T<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> notHave<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token comment\">//mutex 是缓冲区互斥锁,T [i] 是 Qi 进程完成数组,是一个自阻塞数组</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token comment\">//notHave 是缓冲区是否为空,1 就是空,初始没有信息</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token keyword\">int</span> R<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token comment\">//R 是一个计数器</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token function\">Process_P</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>notHave<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> 放入缓冲区<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>i<span class=\"token operator\"><=</span>m<span class=\"token punctuation\">;</span>i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>T<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> R<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre><span class=\"token function\">Process_Qi</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>T<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> 取消息<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> R<span class=\"token operator\">=</span>R<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>R<span class=\"token operator\">==</span>m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>notHave<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"单生产者-单消费者\"><a class=\"markdownIt-Anchor\" href=\"#单生产者-单消费者\">#</a> 单生产者 - 单消费者</h2>\n<p>一组生产者进程和一组消费者进程共享一个初始为空、大小为 n 的缓冲区:只有缓冲区没满时,生产者才能把消息放入缓冲区,否则必须等待:只有缓冲区不空时,消费者才能从中取出消息,否则必须等待。由于缓冲区是临界资源,它只允许一个生产者放入消息,或一个消费者从中取出消息。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore full <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 已生产</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>semaphore empty <span class=\"token operator\">=</span> n<span class=\"token punctuation\">;</span><span class=\"token comment\">// 总可用空间</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span><span class=\"token comment\">// 互斥锁</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token function\">procuder</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> 生产商品<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 假取空间</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 加锁</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> 放入缓冲区<span class=\"token punctuation\">;</span>\t</pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 解锁</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>full<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 告知以生产</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre><span class=\"token function\">consumer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>full<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> 从缓冲区取<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> 消费商品<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"多生产者-多消费者\"><a class=\"markdownIt-Anchor\" href=\"#多生产者-多消费者\">#</a> 多生产者 - 多消费者</h2>\n<p>桌子上有一个盘子,每次只能向其中放入一个水果;爸爸专向盘子中放革果,妈妈专向盘子中放橘子;儿子专等吃盘子中的橘子,女儿专等吃盘子中的革果,只有盘子为空时,爸爸或妈妈才可向盘子中放一个水果,仅当盘子中有自己需要的水果时,儿子或女儿可以从盘子中取出。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 盘子锁</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>semaphore apple <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore orange <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token function\">dad</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> 准备苹果<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> 放苹果<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>apple<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre></pre></td></tr><tr><td data-num=\"14\"></td><td><pre><span class=\"token function\">mom</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> 准备橘子<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> 放橘子<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>orange<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre></pre></td></tr><tr><td data-num=\"23\"></td><td><pre><span class=\"token function\">son</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>orange<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> 拿苹果<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> 吃苹果<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre></pre></td></tr><tr><td data-num=\"32\"></td><td><pre><span class=\"token function\">daughter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>apple<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre> 拿苹果<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre> 吃苹果<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"读者写者问题读优先\"><a class=\"markdownIt-Anchor\" href=\"#读者写者问题读优先\">#</a> 读者写者问题(读优先)</h2>\n<p>有读者和写者两组并发进程,共享一个文件,当两个或以上的读进程同时访问共享数据时不会产生副作用。但若某个写进程和其他进程(读进程或写进程)同时访问共享数据时则可能导致数据不一致的错误。</p>\n<p>因此要求:</p>\n<ol>\n<li>允许多个读者可以同时对文件执行读操作。</li>\n<li>只中许一个写者往文件中写信息。</li>\n<li>任一写者在完成写操作之前不允许其他读者或写者工作。</li>\n<li>写者执行写操作前,应让已有的读者和写者全部退出。</li>\n</ol>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore rw <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">//r-w 读者在读时,不容许其他写者加入。写者在写时,不容许其他读者写者加入。</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token keyword\">int</span> count <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\t\t<span class=\"token comment\">// 记录已加入的读者的数量,如果不为 0,那么其中必有读者,那么其他读者随便加入。</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore count_mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token function\">writer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>rw<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> 写文件<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>rw<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre></pre></td></tr><tr><td data-num=\"12\"></td><td><pre><span class=\"token function\">reader</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>count_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>count <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\t<span class=\"token comment\">// 如果不为 0,那么其中必有读者,那么其他读者随便加入。</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>rw<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 读者为排除其他写者</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> count<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 在线加 1</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>count_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> 读文件<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>count_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> count<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 在线减 1</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>count <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>rw<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>count_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> </pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><p>有可能造成写饥饿</p>\n<h2 id=\"读者写者问题写优先\"><a class=\"markdownIt-Anchor\" href=\"#读者写者问题写优先\">#</a> 读者写者问题(写优先)</h2>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore rw <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token keyword\">int</span> count <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore w <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 写进程霸占</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre></pre></td></tr><tr><td data-num=\"5\"></td><td><pre>semaphore count_mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token function\">writer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 写进程启用霸占</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>rw<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> 写文件<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>rw<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre></pre></td></tr><tr><td data-num=\"16\"></td><td><pre><span class=\"token function\">reader</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 写进程阻碍读进程进入</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>count_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>count <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>rw<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> count<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>count_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> 读文件<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>count_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> count<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>count <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>rw<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>count_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> </pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"吸烟者问题\"><a class=\"markdownIt-Anchor\" href=\"#吸烟者问题\">#</a> 吸烟者问题</h2>\n<p>假设一个系统有三个抽烟者进程和一个供应者进程。每个抽烟者不停地卷烟并抽掉它,但要卷起并抽掉一支烟,抽烟者需要有三种材料:烟草、纸和胶水。三个抽烟者中,第一个拥有烟草,第二个拥有纸,第三个拥有胶水。供应者进程无限地提供三种材料,供应者每次将两种材料放到桌子上,拥有剩下那种材料的抽烟者卷一根烟并抽掉它,并给供应者一个信号告诉已完成,此时供应者就会将另外两种材料放到桌上,如此重复 (让三个抽烟者轮流地抽烟)。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore offer1 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>semaphore offer2 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore offer3 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre>semaphore isFinish <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token function\">provider</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>isFinish<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> \t<span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">%</span><span class=\"token number\">3</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> \t<span class=\"token function\">V</span><span class=\"token punctuation\">(</span>offer1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> \t<span class=\"token punctuation\">}</span><span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">%</span><span class=\"token number\">3</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> \t<span class=\"token function\">V</span><span class=\"token punctuation\">(</span>offer2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> \t<span class=\"token punctuation\">}</span><span class=\"token keyword\">else</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> \t<span class=\"token function\">V</span><span class=\"token punctuation\">(</span>offer3<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> \t<span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> </pre></td></tr><tr><td data-num=\"18\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre></pre></td></tr><tr><td data-num=\"20\"></td><td><pre><span class=\"token function\">somker1</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>offer1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> \t制作香烟<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> \t吸烟<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>isFinish<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token punctuation\">}</span> </pre></td></tr><tr><td data-num=\"27\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre></pre></td></tr><tr><td data-num=\"29\"></td><td><pre><span class=\"token function\">somker2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>offer2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> \t制作香烟<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> \t吸烟<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>isFinish<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre> <span class=\"token punctuation\">}</span> </pre></td></tr><tr><td data-num=\"36\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre></pre></td></tr><tr><td data-num=\"38\"></td><td><pre><span class=\"token function\">somker3</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"40\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>offer3<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"41\"></td><td><pre> \t制作香烟<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"42\"></td><td><pre> \t吸烟<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"43\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>isFinish<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"44\"></td><td><pre> <span class=\"token punctuation\">}</span> </pre></td></tr><tr><td data-num=\"45\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h1 id=\"pv审题流程\"><a class=\"markdownIt-Anchor\" href=\"#pv审题流程\">#</a> PV 审题流程</h1>\n<ol>\n<li>看有几个进程</li>\n<li>进程内部的步骤</li>\n<li>是否需要 while(1)</li>\n<li>哪里有 P?有 P 必有 V</li>\n<li>连续 P 是否会死锁</li>\n<li>定义信号量,写注释</li>\n</ol>\n<h1 id=\"题目实操\"><a class=\"markdownIt-Anchor\" href=\"#题目实操\">#</a> 题目实操</h1>\n<h2 id=\"2020-统考真题\"><a class=\"markdownIt-Anchor\" href=\"#2020-统考真题\">#</a> 2020 统考真题</h2>\n<p>【2020 统考真题】现有 5 个操作 A、B、C、D 和 E,操作 C 必须在 A 和 B 完成后执行操作 E 必须在 C 和 D 完成后执行,请使用信号量的 wait()、signal()操作(P、V 操作)描述上述操作之间的同步关系,并说明所用信号量及其初值。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore ac <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>semaphore bc <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore ce <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre>semaphore ce <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token function\">A</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> 执行任务<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>ac<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre></pre></td></tr><tr><td data-num=\"11\"></td><td><pre><span class=\"token function\">B</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> 执行任务<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>bc<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre></pre></td></tr><tr><td data-num=\"16\"></td><td><pre><span class=\"token function\">C</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>ac<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>bc<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> 执行任务<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>ce<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre></pre></td></tr><tr><td data-num=\"23\"></td><td><pre><span class=\"token function\">D</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> 执行任务<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>de<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre></pre></td></tr><tr><td data-num=\"28\"></td><td><pre><span class=\"token function\">C</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>ce<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>de<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> 执行任务<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><p>【2009 统考真题】三个进程 P1,P2,P3, 互斥使用一个包含 N (N>0) 个单元的缓冲区。</p>\n<ol>\n<li>P1 每次用 produce () 生成一个正整数并用 put () 送入缓冲区某一空单元;</li>\n<li>P2 每次用 getodd () 从该缓冲区中取出一个奇数并用 countodd () 统计奇数个数;</li>\n<li>P3 每次用 geteven () 从该缓冲区中取出一个偶数并用 counteven () 统计偶数个数。</li>\n</ol>\n<p>请用信号量机制实现这三个进程的同步与互斥活动,并说明所定义的信号量的含义 (要求用伪代码描述)。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>semaphore odd <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore even <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token function\">P1</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token keyword\">int</span> num <span class=\"token operator\">=</span> <span class=\"token function\">produce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>num<span class=\"token operator\">%</span><span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token function\">put</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>even<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token punctuation\">}</span><span class=\"token keyword\">else</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token function\">put</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>odd<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre></pre></td></tr><tr><td data-num=\"22\"></td><td><pre><span class=\"token function\">P2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>odd<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token function\">getodd</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token function\">countodd</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre></pre></td></tr><tr><td data-num=\"32\"></td><td><pre><span class=\"token function\">P2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>even<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> <span class=\"token function\">geteven</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre> <span class=\"token function\">counteven</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"40\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"2011-统考真题\"><a class=\"markdownIt-Anchor\" href=\"#2011-统考真题\">#</a> 2011 统考真题</h2>\n<p>【2011 统考真题】某银行提供 1 个服务窗口和 10 个供顾客等待的座位。顾客到达银行时若有空座位,则到取号机上领取一个号,等待叫号。取号机每次仅允许一位顾客使用。当营业员空闲时,通过叫号选取一位顾客,并为其服务。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore count <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>semaphore mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore server <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre>semaphore full <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token function\">customer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> \t从取号机取号<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> \t<span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> \t<span class=\"token function\">V</span><span class=\"token punctuation\">(</span>full<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> \t等待叫号<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> \t<span class=\"token function\">P</span><span class=\"token punctuation\">(</span>server<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> \t获取服务<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> </pre></td></tr><tr><td data-num=\"18\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre><span class=\"token function\">clerk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>full<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> 叫号<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>server<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> 服务<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token punctuation\">}</span> </pre></td></tr><tr><td data-num=\"27\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"809-24年-真题\"><a class=\"markdownIt-Anchor\" href=\"#809-24年-真题\">#</a> 809-24 年 真题</h2>\n<p>崂山有一景点称作上清宫,游客在上清宫游玩后可以在宫门口免费搭乘轿车游览其他景区,游览后再返回宫门口。已知风景区游览轿车总量有 M 量,游客总数为 N,约定:</p>\n<ol>\n<li>每辆轿车限乘一位游客;</li>\n<li>如果有空闲的轿车,应当允许想游览的游客乘坐;</li>\n<li>无空闲轿车时,游客只能排队等待;</li>\n<li>若没有想游览的游客,空闲的轿车也要等待。</li>\n</ol>\n<p>试利用 P、V 操作实现在上清宫门口乘车点:N 个游客进程和 M 辆轿车进程的同步操作过程。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>semaphore car <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> \t\t<span class=\"token comment\">// 空闲车辆数量</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore customer <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 等待乘车的游客数量</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token comment\">//M 个车辆进程</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token function\">car</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> 等待游客<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>customer<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t<span class=\"token comment\">// 等待有游客请求乘车</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t\t<span class=\"token comment\">// 进入临界区</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t\t\t<span class=\"token comment\">// 提供一辆空闲轿车</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t\t<span class=\"token comment\">// 离开临界区</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> 接待游览<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> 释放游客<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre></pre></td></tr><tr><td data-num=\"19\"></td><td><pre><span class=\"token comment\">//N 个游客进程</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre><span class=\"token function\">customer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> 等待车辆<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t\t\t<span class=\"token comment\">// 等待空闲轿车</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> \t<span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t\t<span class=\"token comment\">// 进入临界区</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>customer<span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">// 通知有游客请求乘车</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\t\t<span class=\"token comment\">// 离开临界区</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> 上车游览<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> 离开<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"典例-和尚打水\"><a class=\"markdownIt-Anchor\" href=\"#典例-和尚打水\">#</a> 典例 和尚打水</h2>\n<p>某寺庙有小和尚、老和尚若干,有一水缸,由小和尚提水入缸供老和尚饮用。水缸可容 10 桶水,水取自同一井中。水井径窄,每次只能容一个桶取水。水桶总数为 3 个。每次入缸取水仅为 1 桶水,且不可同时进行,试给出有关从缸取水、入水的算法描述。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore total_empty <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>semaphore total_full <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore mutex_jing <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre>semaphore mutex_gang <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre>demaphore bucket <span class=\"token operator\">=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token function\">Old</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>total_full<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>bucket<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex_gang<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> 从缸里取水<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>total_empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex_gang<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre>\t喝水<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>bucket<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre></pre></td></tr><tr><td data-num=\"17\"></td><td><pre><span class=\"token function\">Young</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>total_empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>bucket<span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex_jing<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> 从水井取水<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex_jing<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>mutex_gang<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre>\t倒进缸里<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>total_full<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>mutex_gang<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>bucket<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> </pre></td></tr><tr><td data-num=\"29\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"典例-公交车售票\"><a class=\"markdownIt-Anchor\" href=\"#典例-公交车售票\">#</a> 典例 公交车售票</h2>\n<p>设公共汽车上,司机和售票员的活动分别是:</p>\n<ol>\n<li>司机的活动:启动车辆;正常行车;到站停车;</li>\n<li>售票员的活动:关车门;售票;开车门;</li>\n</ol>\n<p>请用记录型信号量机制实现上述问题的同步。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore door_mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>semaphore start_mutex <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token function\">driver</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>start_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> 启动车辆<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> 正常行车<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> 到站停车<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>door_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre><span class=\"token function\">busman</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>door_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> 开车门<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> 售票<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> 关车门<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>start_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"典例-独木桥问题\"><a class=\"markdownIt-Anchor\" href=\"#典例-独木桥问题\">#</a> 典例 独木桥问题</h2>\n<p>请用信号量解决以下的 “过独木桥” 问题:同一方向的行人可连续过桥,当某一方向有人过桥时,另一方向的行人必须等待;当某一方向无人过桥时,另一方向的行人可以过桥。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore isOK <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token keyword\">int</span> toACount <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token keyword\">int</span> toBCount <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre>semaphore toACount_mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre>semaphore toBCount_mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre></pre></td></tr><tr><td data-num=\"7\"></td><td><pre></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token function\">toA</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>toACount_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>toACount <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>isOK<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> toACount<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>toACount_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> 上桥走向A<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>toACount_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> toACount<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>toACount <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>isOK<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>toACount_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre></pre></td></tr><tr><td data-num=\"24\"></td><td><pre><span class=\"token function\">toB</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>toBCount_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>toBCount <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>isOK<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> toBCount<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre>\t<span class=\"token function\">V</span><span class=\"token punctuation\">(</span>toBCount_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> 上桥走向B<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>toBCount_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> toBCount<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>toBCount <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>isOK<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre>\t<span class=\"token function\">V</span><span class=\"token punctuation\">(</span>toBCount_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"典例-阅览室问题\"><a class=\"markdownIt-Anchor\" href=\"#典例-阅览室问题\">#</a> 典例 阅览室问题</h2>\n<p>有一阅览室,共有 100 个座位。为了很好利用它,读者进入时必须先在登记表上进行登记。该表表目设有座位号和读者姓名;离开时再将其登记项摈除。试问:</p>\n<ol>\n<li>为描述读者的动作,应设哪几个进程?它们之间的关系是什么?</li>\n<li>试用 P、V 操作描述进程之间的同步或算法。</li>\n</ol>\n<p>答:要设读者进入进程和离开进程,总计两个进程。他们是互斥关系。</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>semaphore seats <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>semaphore readers <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore table_mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token function\">getIn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>seats<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>table_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> 登记<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>table_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>readers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre><span class=\"token function\">getOut</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>readers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>table_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> 移除登记<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>table_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>seats<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"典例-考试问题\"><a class=\"markdownIt-Anchor\" href=\"#典例-考试问题\">#</a> 典例 考试问题</h2>\n<p>《操作系统》课程的期末考试即将举行,假设把学生和监考老师都看作进程,学生有 N 人,教师 1 人。考场门口每次只能进出一个人,进考场的原则是先来先进。当 N 个学生都进入了考场后,教师才能发卷子。学生交卷后即可离开考场,而教师要等收上来全部卷子并封装卷子后才能离开考场。</p>\n<p>(1) 问共需设置几个进程?</p>\n<p>(2) 请用 P、V 操作解决上述问题中的同步和互斥关系。</p>\n<p>答:共设置 N+1 个进程,一个教师进程,N 个学生进程</p>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">int</span> studentCount <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token keyword\">int</span> onPageCount <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>semaphore door_mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre>semaphore startTest <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre>semaphore endTest <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre>semaphore readyToTest <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre>semaphore onPageCount_mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre>semaphore allStudentsOK <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre></pre></td></tr><tr><td data-num=\"10\"></td><td><pre><span class=\"token function\">teacher</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>door_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> 进门<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>door_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>readyToTest<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> 发卷子<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>startTest<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> 监考<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>allStudentsOK<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> 整理试卷<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>door_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> 出门<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>door_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre></pre></td></tr><tr><td data-num=\"25\"></td><td><pre><span class=\"token function\">students</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>door_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> 进门<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> studentCount<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>studentCont <span class=\"token operator\">==</span> N<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>readyToTest<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>door_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>startTest<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre> 开始答题<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>onPageCount_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> 交卷<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre> onPageCount<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>onPageCount <span class=\"token operator\">==</span> N<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>allStudentsOK<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"40\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"41\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>onPageCount_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"42\"></td><td><pre> <span class=\"token function\">P</span><span class=\"token punctuation\">(</span>door_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"43\"></td><td><pre> 出门<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"44\"></td><td><pre> studentCount<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"45\"></td><td><pre> <span class=\"token function\">V</span><span class=\"token punctuation\">(</span>door_mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"46\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><div class=\"links\"><div class=\"item\" title=\"hunter_wyh\" style=\"--block-color:#e9546b;\"><span class=\"exturl image\" data-url=\"aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2h1bnRlcl93eWgvYXJ0aWNsZS9kZXRhaWxzLzQ5NzY0MTc1\" data-background-image=\"/images/404.png\"></span>\n <div class=\"info\">\n <span class=\"exturl title\" data-url=\"aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2h1bnRlcl93eWgvYXJ0aWNsZS9kZXRhaWxzLzQ5NzY0MTc1\">hunter_wyh CSDN 博客</span>\n <p class=\"desc\">部分题目出自此博客</p>\n </div></div></div>",
"tags": [
"操作系统",
"OS"
]
},
{
"id": "https://735690757.github.io/DSLearnNote/codeTM/",
"url": "https://735690757.github.io/DSLearnNote/codeTM/",
"title": "数据结构代码题速记",
"date_published": "2024-09-10T03:00:00.000Z",
"content_html": "<h1 id=\"线性表方向\"><a class=\"markdownIt-Anchor\" href=\"#线性表方向\">#</a> 线性表方向</h1>\n<h2 id=\"链表的合并\"><a class=\"markdownIt-Anchor\" href=\"#链表的合并\">#</a> 链表的合并</h2>\n<div class=\"note primary no-icon\">\n<p>设计实现将两个带有头节点的有序链表合并为一个新的有序链表。</p>\n</div>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">marge</span><span class=\"token punctuation\">(</span>LNode <span class=\"token operator\">*</span>A<span class=\"token punctuation\">,</span>LNode <span class=\"token operator\">*</span>B<span class=\"token punctuation\">,</span>LNode <span class=\"token operator\">*</span>C<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> LNode p <span class=\"token operator\">=</span> A<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> LNode q <span class=\"token operator\">=</span> B<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> LNode r<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> r<span class=\"token operator\">-></span>next <span class=\"token operator\">=</span> null<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> C <span class=\"token operator\">=</span> A<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> r<span class=\"token operator\">=</span>c<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>p <span class=\"token operator\">!=</span> null<span class=\"token operator\">||</span>q <span class=\"token operator\">!=</span> null<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>p<span class=\"token operator\">-></span>data <span class=\"token operator\"><=</span> q<span class=\"token operator\">-></span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> r<span class=\"token operator\">-></span>next <span class=\"token operator\">=</span> p<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> p <span class=\"token operator\">=</span> p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> r <span class=\"token operator\">=</span> r<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> r<span class=\"token operator\">-></span>next <span class=\"token operator\">=</span> q<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> q <span class=\"token operator\">=</span> q<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> r <span class=\"token operator\">=</span> r<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span> r <span class=\"token operator\">=</span> p<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>q<span class=\"token punctuation\">)</span> r <span class=\"token operator\">=</span> q<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"链表的逆置\"><a class=\"markdownIt-Anchor\" href=\"#链表的逆置\">#</a> 链表的逆置</h2>\n<div class=\"note primary no-icon\">\n<p>设计实现将无头节点链表进行逆置</p>\n</div>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">invert</span><span class=\"token punctuation\">(</span>LinkList <span class=\"token operator\">&</span>L<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> p<span class=\"token operator\">=</span>L<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> q<span class=\"token operator\">=</span>p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> r<span class=\"token operator\">=</span>q<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> q<span class=\"token operator\">-></span>next<span class=\"token operator\">=</span>p<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> p<span class=\"token operator\">=</span>q<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> q<span class=\"token operator\">=</span>r<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> L<span class=\"token operator\">-></span>next<span class=\"token operator\">=</span>null<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> L<span class=\"token operator\">=</span>p<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"顺序表的逆置\"><a class=\"markdownIt-Anchor\" href=\"#顺序表的逆置\">#</a> 顺序表的逆置</h2>\n<div class=\"note primary no-icon\">\n<p>设计一个算法,将顺序表 L 所有的元素逆置,要求算法效率尽可能地高。</p>\n</div>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span>Sqlist <span class=\"token operator\">&</span>L<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> ElemType temp<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\"><</span>L<span class=\"token punctuation\">.</span>length<span class=\"token operator\">/</span><span class=\"token number\">2</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> temp <span class=\"token operator\">=</span> L<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> L<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>L<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">[</span>L<span class=\"token punctuation\">.</span>length<span class=\"token operator\">-</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> L<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">[</span>L<span class=\"token punctuation\">.</span>length<span class=\"token operator\">-</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><div class=\"note info\">\n<p>一种” 就地 “思想</p>\n</div>\n<h2 id=\"统计单链表hl中的值等于x的个数\"><a class=\"markdownIt-Anchor\" href=\"#统计单链表hl中的值等于x的个数\">#</a> 统计单链表 HL 中的值等于 x 的个数</h2>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">int</span> <span class=\"token function\">countX</span><span class=\"token punctuation\">(</span>LNode <span class=\"token operator\">*</span>HL<span class=\"token punctuation\">,</span> ElemType x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">int</span> countNum <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> LNode p <span class=\"token operator\">=</span> HL<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>p<span class=\"token operator\">-></span>data <span class=\"token operator\">==</span> x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> countNum<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> p <span class=\"token operator\">=</span> p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token keyword\">return</span> countNum<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> </pre></td></tr><tr><td data-num=\"12\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"hl是单链表的头指针删除头节点\"><a class=\"markdownIt-Anchor\" href=\"#hl是单链表的头指针删除头节点\">#</a> HL 是单链表的头指针,删除头节点</h2>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>ElemType <span class=\"token function\">DeleFront</span><span class=\"token punctuation\">(</span>LNode <span class=\"token operator\">*</span><span class=\"token operator\">&</span>HL<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>HL <span class=\"token operator\">==</span> null<span class=\"token punctuation\">)</span> <span class=\"token function\">exit</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> LNode <span class=\"token operator\">*</span>p <span class=\"token operator\">=</span> HL<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> ElemType con <span class=\"token operator\">=</span> p<span class=\"token operator\">-></span>data<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> p<span class=\"token operator\">-></span>next <span class=\"token operator\">=</span> p<span class=\"token operator\">-></span>netx<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">return</span> com<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"判断单链表是否中心对称\"><a class=\"markdownIt-Anchor\" href=\"#判断单链表是否中心对称\">#</a> 判断单链表是否中心对称</h2>\n<div class=\"note primary no-icon\">\n<ol>\n<li>链表计数</li>\n<li>动态开辟数组(逻辑栈)</li>\n<li>奇数个要跳过最中心的那个元素</li>\n<li>链表向后,栈向下依次检查</li>\n<li>结束前记得 free 栈</li>\n</ol>\n</div>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">bool</span> <span class=\"token function\">isDC</span><span class=\"token punctuation\">(</span>LinkList <span class=\"token operator\">*</span>L<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>L <span class=\"token operator\">==</span> <span class=\"token constant\">NULL</span> <span class=\"token operator\">||</span> L<span class=\"token operator\">-></span>next <span class=\"token operator\">==</span> <span class=\"token constant\">NULL</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token comment\">// 计算链表长度</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token keyword\">int</span> count <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> LinkList <span class=\"token operator\">*</span>p <span class=\"token operator\">=</span> L<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> count<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> p <span class=\"token operator\">=</span> p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token comment\">// 动态分配栈空间</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token keyword\">int</span> <span class=\"token operator\">*</span>stack <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> <span class=\"token operator\">*</span><span class=\"token punctuation\">)</span><span class=\"token function\">malloc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>count <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">sizeof</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>stack <span class=\"token operator\">==</span> <span class=\"token constant\">NULL</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> p <span class=\"token operator\">=</span> L<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token keyword\">int</span> top <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> count <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> stack<span class=\"token punctuation\">[</span><span class=\"token operator\">++</span>top<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> p<span class=\"token operator\">-></span>data<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> p <span class=\"token operator\">=</span> p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token comment\">// 如果链表长度为奇数,跳过中间的节点</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">!=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> p <span class=\"token operator\">=</span> p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token comment\">// 开始比较</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>p<span class=\"token operator\">-></span>data <span class=\"token operator\">!=</span> stack<span class=\"token punctuation\">[</span>top<span class=\"token operator\">--</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token function\">free</span><span class=\"token punctuation\">(</span>stack<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> p <span class=\"token operator\">=</span> p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre></pre></td></tr><tr><td data-num=\"35\"></td><td><pre> <span class=\"token function\">free</span><span class=\"token punctuation\">(</span>stack<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"链表a链表b求a与b的交集生成链表c\"><a class=\"markdownIt-Anchor\" href=\"#链表a链表b求a与b的交集生成链表c\">#</a> 链表 A,链表 B,求 A 与 B 的交集生成链表 C</h2>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">bool</span> <span class=\"token function\">isExistence</span><span class=\"token punctuation\">(</span>LinkList <span class=\"token operator\">*</span>L<span class=\"token punctuation\">,</span>Elemtype goData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>L<span class=\"token operator\">==</span>null<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> LinkList <span class=\"token operator\">*</span>p <span class=\"token operator\">=</span> L<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>p<span class=\"token operator\">-></span>data <span class=\"token operator\">==</span> goData<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> p<span class=\"token operator\">=</span>p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">intersectionAB</span><span class=\"token punctuation\">(</span>LinkList <span class=\"token operator\">*</span>A<span class=\"token punctuation\">,</span>LinkList <span class=\"token operator\">*</span>B<span class=\"token punctuation\">,</span>LinkList <span class=\"token operator\">*</span><span class=\"token operator\">&</span>C<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> LinkList <span class=\"token operator\">*</span>a<span class=\"token operator\">=</span>A<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> LinkList <span class=\"token operator\">*</span>b<span class=\"token operator\">=</span>B<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> LinkList <span class=\"token operator\">*</span>c<span class=\"token operator\">=</span>C<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> LinkList go<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> LinkList <span class=\"token operator\">*</span>goP<span class=\"token operator\">=</span>go<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> </pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>a<span class=\"token operator\">-></span>data<span class=\"token operator\">==</span>b<span class=\"token operator\">-></span>data<span class=\"token operator\">&&</span><span class=\"token function\">isExistence</span><span class=\"token punctuation\">(</span>goP<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> c <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>LinkList<span class=\"token operator\">*</span><span class=\"token punctuation\">)</span><span class=\"token function\">malloc</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">sizeof</span><span class=\"token punctuation\">(</span>LinkList<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> go <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>LinkList<span class=\"token operator\">*</span><span class=\"token punctuation\">)</span><span class=\"token function\">malloc</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">sizeof</span><span class=\"token punctuation\">(</span>LinkList<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> c<span class=\"token operator\">-></span>data <span class=\"token operator\">=</span> b<span class=\"token operator\">-></span>data<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> c <span class=\"token operator\">=</span> c<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> goP <span class=\"token operator\">=</span> goP<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> b <span class=\"token operator\">=</span> b<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> a <span class=\"token operator\">=</span> a<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> b <span class=\"token operator\">=</span> B<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"设计单链表中值相同的多余节点\"><a class=\"markdownIt-Anchor\" href=\"#设计单链表中值相同的多余节点\">#</a> 设计单链表中值相同的多余节点</h2>\n<div class=\"note primary no-icon\">\n<p>这段代码可能存在内存泄漏的风险,应对考试应该还是没问题的</p>\n</div>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">deleteCon</span><span class=\"token punctuation\">(</span>LinkList <span class=\"token operator\">*</span><span class=\"token operator\">&</span>L<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>L<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> LinkList <span class=\"token operator\">*</span>p <span class=\"token operator\">=</span> L<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> LinkList <span class=\"token operator\">*</span>q<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> LinkList <span class=\"token operator\">*</span>r<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">int</span> num <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> num<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> p <span class=\"token operator\">=</span> p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> p <span class=\"token operator\">=</span> L<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token keyword\">int</span><span class=\"token operator\">*</span> nodeHave <span class=\"token operator\">=</span> <span class=\"token function\">malloc</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">sizeof</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span><span class=\"token punctuation\">)</span><span class=\"token operator\">*</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token keyword\">int</span> now<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> nodeHave<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>p<span class=\"token operator\">-></span>data<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> q<span class=\"token operator\">=</span>p<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> p<span class=\"token operator\">=</span>p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token keyword\">bool</span> found <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">;</span>i<span class=\"token operator\"><</span>now<span class=\"token punctuation\">;</span>i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>nodeHave<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> p<span class=\"token operator\">-></span>data<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> q<span class=\"token operator\">-></span>next<span class=\"token operator\">=</span>q<span class=\"token operator\">-></span>next<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> q<span class=\"token operator\">=</span>q<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> p<span class=\"token operator\">=</span>p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> r<span class=\"token operator\">=</span>p<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token function\">free</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> found <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>found<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> nodeHave<span class=\"token punctuation\">[</span>now<span class=\"token operator\">++</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>p<span class=\"token operator\">-></span>data<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> \tp<span class=\"token operator\">=</span>p<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> \tq<span class=\"token operator\">=</span>q<span class=\"token operator\">-></span>next<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token punctuation\">}</span> </pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token punctuation\">}</span> </pre></td></tr><tr><td data-num=\"35\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h1 id=\"树方向\"><a class=\"markdownIt-Anchor\" href=\"#树方向\">#</a> 树方向</h1>\n<h2 id=\"二叉树求树高\"><a class=\"markdownIt-Anchor\" href=\"#二叉树求树高\">#</a> 二叉树求树高</h2>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">int</span> <span class=\"token function\">getDeep</span><span class=\"token punctuation\">(</span>BTree b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">int</span> HL<span class=\"token punctuation\">,</span>HR<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> HL <span class=\"token operator\">=</span> HR <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> HL <span class=\"token operator\">=</span> <span class=\"token function\">getDeep</span><span class=\"token punctuation\">(</span>b<span class=\"token operator\">-></span>Lchild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> HR <span class=\"token operator\">=</span> <span class=\"token function\">getDeep</span><span class=\"token punctuation\">(</span>b<span class=\"token operator\">-></span>Rchild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">return</span> HL <span class=\"token operator\">></span> HR <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>HL<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>HR<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token comment\">// 此处 return 就是谁大就返回谁加一</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"左孩子友兄弟表示法求原树高\"><a class=\"markdownIt-Anchor\" href=\"#左孩子友兄弟表示法求原树高\">#</a> 左孩子友兄弟表示法,求原树高</h2>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">int</span> <span class=\"token function\">hight</span><span class=\"token punctuation\">(</span>BTree b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">int</span> HL<span class=\"token punctuation\">,</span>HR<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> HL <span class=\"token operator\">=</span> HR <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>b <span class=\"token operator\">==</span> <span class=\"token constant\">NULL</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> HL <span class=\"token operator\">=</span> <span class=\"token function\">high</span><span class=\"token punctuation\">(</span>b<span class=\"token operator\">-></span>Lchild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> HR <span class=\"token operator\">=</span> <span class=\"token function\">high</span><span class=\"token punctuation\">(</span>b<span class=\"token operator\">-></span>Rchild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>HL<span class=\"token operator\">+</span><span class=\"token number\">1</span> <span class=\"token operator\">></span> HR<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token keyword\">return</span> HL <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token keyword\">return</span> HR<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> </pre></td></tr><tr><td data-num=\"13\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"二叉树求树宽\"><a class=\"markdownIt-Anchor\" href=\"#二叉树求树宽\">#</a> 二叉树求树宽</h2>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">int</span> count<span class=\"token punctuation\">[</span><span class=\"token number\">100</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token keyword\">int</span> max <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">width</span><span class=\"token punctuation\">(</span>BTree t<span class=\"token punctuation\">,</span><span class=\"token keyword\">int</span> k<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> <span class=\"token constant\">NULL</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> count<span class=\"token punctuation\">[</span>k<span class=\"token punctuation\">]</span> <span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>max <span class=\"token operator\"><</span> count<span class=\"token punctuation\">[</span>k<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> max <span class=\"token operator\">=</span> count<span class=\"token punctuation\">[</span>k<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token function\">width</span><span class=\"token punctuation\">(</span>t<span class=\"token operator\">-></span>lchild<span class=\"token punctuation\">,</span> k<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">width</span><span class=\"token punctuation\">(</span>t<span class=\"token operator\">-></span>rchild<span class=\"token punctuation\">,</span> k<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"链式存储结构建立二叉树\"><a class=\"markdownIt-Anchor\" href=\"#链式存储结构建立二叉树\">#</a> 链式存储结构建立二叉树</h2>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">typedef</span> <span class=\"token keyword\">char</span> datatype<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token keyword\">typedef</span> <span class=\"token keyword\">struct</span> <span class=\"token class-name\">node</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> datatype data<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token keyword\">struct</span> <span class=\"token class-name\">node</span> <span class=\"token operator\">*</span>lchild<span class=\"token punctuation\">,</span><span class=\"token operator\">*</span>rchild<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token punctuation\">}</span>btree</pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">createBtree</span><span class=\"token punctuation\">(</span>btree <span class=\"token operator\">*</span><span class=\"token operator\">&</span>bt<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> datatype zData<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token function\">scanf</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"%c\"</span><span class=\"token punctuation\">,</span><span class=\"token operator\">&</span>zData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>zData <span class=\"token operator\">==</span> <span class=\"token char\">'#'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> bt<span class=\"token operator\">=</span>null<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> bt <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>btree<span class=\"token operator\">*</span><span class=\"token punctuation\">)</span><span class=\"token function\">malloc</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">sizeof</span><span class=\"token punctuation\">(</span>btree<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> bt<span class=\"token operator\">-></span>data<span class=\"token operator\">=</span>zData<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token function\">createBtree</span><span class=\"token punctuation\">(</span>bt<span class=\"token operator\">-></span>lchild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token function\">createBtree</span><span class=\"token punctuation\">(</span>bt<span class=\"token operator\">-></span>rchild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"判断二叉树是否为排序二叉树二叉搜索树\"><a class=\"markdownIt-Anchor\" href=\"#判断二叉树是否为排序二叉树二叉搜索树\">#</a> 判断二叉树是否为排序二叉树 / 二叉搜索树</h2>\n<div class=\"note primary no-icon\">\n<p>判断一棵二叉树是否为排序二叉树,可以通过中序遍历来实现。在 BST 中,中序遍历的结果应该是一个严格递增的序列。如果遍历过程中发现任何一个节点的值不大于前一个节点的值,则该树不是 BST。</p>\n</div>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">int</span> minnum <span class=\"token operator\">=</span> INT_MIN<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token keyword\">int</span> isFirstNode <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 标记是否是第一个节点 (最左侧的节点)</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token keyword\">int</span> <span class=\"token function\">isBST</span><span class=\"token punctuation\">(</span>BTree <span class=\"token operator\">*</span>bt<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>bt<span class=\"token operator\">==</span>null<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span><span class=\"token comment\">// 空树是 BST</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">isBST</span><span class=\"token punctuation\">(</span>bt<span class=\"token operator\">-></span>lchild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>isFirstNode <span class=\"token operator\">&&</span> bt<span class=\"token operator\">-></span>data<span class=\"token operator\"><</span>minnum<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> isFirstNode <span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> minnum <span class=\"token operator\">=</span> bt<span class=\"token operator\">-></span>data<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token function\">isBST</span><span class=\"token punctuation\">(</span>bt<span class=\"token operator\">-></span>rchild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> </pre></td></tr><tr><td data-num=\"18\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h1 id=\"排序方向\"><a class=\"markdownIt-Anchor\" href=\"#排序方向\">#</a> 排序方向</h1>\n<h2 id=\"快速排序\"><a class=\"markdownIt-Anchor\" href=\"#快速排序\">#</a> 快速排序</h2>\n<h3 id=\"快速排序分区函数\"><a class=\"markdownIt-Anchor\" href=\"#快速排序分区函数\">#</a> 快速排序分区函数</h3>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">int</span> <span class=\"token function\">Partition</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> a<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span><span class=\"token keyword\">int</span> low<span class=\"token punctuation\">,</span><span class=\"token keyword\">int</span> high<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">int</span> flag <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>low<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>low <span class=\"token operator\"><</span> high<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>low <span class=\"token operator\"><</span> high <span class=\"token operator\">&&</span> flag <span class=\"token operator\"><=</span> a<span class=\"token punctuation\">[</span>high<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">--</span>high<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> a<span class=\"token punctuation\">[</span>low<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>high<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>low <span class=\"token operator\"><</span> high <span class=\"token operator\">&&</span> flag <span class=\"token operator\">></span> a<span class=\"token punctuation\">[</span>low<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">++</span>low<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> a<span class=\"token punctuation\">[</span>high<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>low<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> a<span class=\"token punctuation\">[</span>low<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> flag<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token keyword\">return</span> low<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h3 id=\"快速排序递归函数\"><a class=\"markdownIt-Anchor\" href=\"#快速排序递归函数\">#</a> 快速排序递归函数</h3>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">QuickSort</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> a<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span><span class=\"token keyword\">int</span> low<span class=\"token punctuation\">,</span><span class=\"token keyword\">int</span> high<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>low <span class=\"token operator\"><</span> high<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> <span class=\"token keyword\">int</span> pivo <span class=\"token operator\">=</span> <span class=\"token function\">Partition</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>low<span class=\"token punctuation\">,</span>high<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token function\">QuickSort</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>low<span class=\"token punctuation\">,</span>pivo<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token function\">QuickSort</span><span class=\"token punctuation\">(</span>apivo<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>high<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h1 id=\"综合代码题目\"><a class=\"markdownIt-Anchor\" href=\"#综合代码题目\">#</a> 综合代码题目</h1>\n<h2 id=\"快速排序分区函数-顺序表移动\"><a class=\"markdownIt-Anchor\" href=\"#快速排序分区函数-顺序表移动\">#</a> 快速排序分区函数 + 顺序表移动</h2>\n<div class=\"note primary no-icon\">\n<p>设计一个算法,调整数组 a [] 中的元素并返回分界值,使所有小于 x 的元素都出现在其左边(a [1…i]),所有大于 x 的元素都出现在其右边(a [i+1…n])。</p>\n</div>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"><span>不严谨的代码</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">int</span> <span class=\"token function\">div</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> a<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>intx<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">int</span> rear <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span></pre></td></tr><tr class=\"marked\"><td data-num=\"3\"></td><td><pre> a<span class=\"token punctuation\">[</span>rear<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> x<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token keyword\">int</span> start <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>start <span class=\"token operator\"><</span> rear<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>start<span class=\"token operator\"><</span>rear <span class=\"token operator\">&&</span> x<span class=\"token operator\">>=</span>a<span class=\"token punctuation\">[</span>start<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> rear<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> a<span class=\"token punctuation\">[</span>rear<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>start<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>start<span class=\"token operator\"><</span>rear <span class=\"token operator\">&&</span> x<span class=\"token operator\"><</span>a<span class=\"token punctuation\">[</span>rear<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> start<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> a<span class=\"token punctuation\">[</span>strat<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>rear<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> start<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> j<span class=\"token operator\">=</span>i<span class=\"token punctuation\">;</span> j<span class=\"token operator\">></span><span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> a<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>a<span class=\"token punctuation\">[</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token keyword\">return</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><div class=\"note danger\">\n<p>实际上,上述代码有一些不严谨的部分,比如,可能造成数组越界。<br>\n但仍然可以帮助我们拿下绝大部分的分数。</p>\n</div>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"><span>相同逻辑更严谨的代码</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">int</span> <span class=\"token function\">div</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> a<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span><span class=\"token keyword\">int</span> h<span class=\"token punctuation\">,</span><span class=\"token keyword\">int</span> x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token keyword\">int</span> i<span class=\"token punctuation\">,</span>j<span class=\"token punctuation\">,</span>t<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> j <span class=\"token operator\">=</span> h<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\"><</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token comment\">// 找到第一个小于等于 x 的元素</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\"><</span>j <span class=\"token operator\">&&</span> a<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token operator\">>=</span>x<span class=\"token punctuation\">)</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token comment\">// 找到第一个大于 x 的元素</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\"><</span>j <span class=\"token operator\">&&</span> a<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token operator\"><=</span>x<span class=\"token punctuation\">)</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\"><</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token comment\">// 交换元素</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> t <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> a<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> a<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> t<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token comment\">// 这里可能会出现 i 跨越 j 的情况,这里做下判断</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token comment\">// 如果 i 位置的数仍然比 x 要小,那么就可以返回 i</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token comment\">// 反之就是 i 跨越了 j,而且最多只会跨越一步,返回 i-1</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token operator\"><</span>x<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token keyword\">else</span> <span class=\"token keyword\">return</span> i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><div class=\"note success\">\n<p>上述代码体现就是一种类似 “就地算法” 的思想,无需借助辅助空间。<br>\n找到第一个大于 x 与小于 x 的数,直接原地交换位置,然后继续寻找。</p>\n</div>\n",
"tags": [
"DS",
"数据结构"
]
},
{
"id": "https://735690757.github.io/Operate-system/KnowledgeSummary/",
"url": "https://735690757.github.io/Operate-system/KnowledgeSummary/",
"title": "操作系统细碎知识点及公式速记",
"date_published": "2024-09-09T12:41:00.000Z",
"content_html": "<h1 id=\"操作系统细碎知识点总结\"><a class=\"markdownIt-Anchor\" href=\"#操作系统细碎知识点总结\">#</a> 操作系统细碎知识点总结</h1>\n<ol>\n<li>现代操作系统两个最基本特征:<span class=\"label primary\">并发</span> 与 <span class=\"label primary\">共享</span></li>\n<li>OS 主要特征是:<span class=\"label primary\">并发</span>、<span class=\"label primary\">共享</span>、<span class=\"label primary\">虚拟</span> 以及 <span class=\"label primary\">异步</span></li>\n<li>操作系统出现的标志:<span class=\"label primary\">多道程序设计</span> 以及 <span class=\"label primary\">分时操作系统</span> 的出现</li>\n<li>高级调度:<span class=\"label primary\">作业调度</span></li>\n<li>中级调度:<span class=\"label primary\">内存调度</span></li>\n<li>低级调度:<span class=\"label primary\">进程调度</span></li>\n<li>多级存储分为三部分:<span class=\"label primary\">高速缓存</span>、<span class=\"label primary\">内存 / 主存</span> 以及 <span class=\"label primary\">外存</span></li>\n<li>进程的调度时机:<span class=\"label primary\">时间片完</span>、<span class=\"label primary\">正常结束</span>、<span class=\"label primary\">P 操作</span>、<span class=\"label primary\">IO 请求</span> 以及 <span class=\"label primary\">优先级抢占</span></li>\n<li>文件系统的功能:<span class=\"label primary\">按名存取</span>、<span class=\"label primary\">存储空间管理</span>、<span class=\"label primary\">文件共享与保护</span> 以及 <span class=\"label primary\">文件操作</span></li>\n<li>SPOOLING 系统的组成:<span class=\"label primary\">输入进程</span>、<span class=\"label primary\">输入缓冲区</span>、<span class=\"label primary\">输入井</span>、<span class=\"label primary\">输出进程</span>、<span class=\"label primary\">输出缓冲区</span> 以及 <span class=\"label primary\">输出井</span></li>\n<li>进程的结构特征(有争议 / 不严谨):<span class=\"label primary\">独立性</span>、<span class=\"label primary\">动态性</span>、<span class=\"label primary\">异步性</span> 以及 <span class=\"label primary\">并发性</span></li>\n<li>虚拟存储器的主要特征:<span class=\"label primary\">多次性</span>、<span class=\"label primary\">对换性</span> 以及 <span class=\"label primary\">虚拟性</span></li>\n<li>所学的进程调度算法中,最中庸、最能让长作业和短作业都满意的调度算法是:<span class=\"label primary\">多级反馈队列调度算法</span></li>\n<li>进程是<span class=\"label primary\">资源分配</span>的基本单位,线程是<span class=\"label primary\">调度</span>的基本单位</li>\n<li>程序的几种装入方式:<span class=\"label primary\">静态装入</span>、<span class=\"label primary\">可重定位装入</span> 以及 <span class=\"label primary\">动态运行时装入</span></li>\n<li>程序的几种链接方式:<span class=\"label primary\">静态链接</span>、<span class=\"label primary\">装入时动态链接</span> 以及 <span class=\"label primary\">运行时动态链接</span></li>\n<li>程序的顺序执行的特征:<span class=\"label primary\">顺序性</span>、<span class=\"label primary\">封闭性</span> 以及 <span class=\"label primary\">结果可再现性</span></li>\n<li>请求分页式虚拟存储系统必须至少具有三种硬件支持,即<span class=\"label primary\">页表机制</span>、<span class=\"label primary\">缺页中断机构</span> 以及 <span class=\"label primary\">地址变换机构</span></li>\n<li>程序并发执行的特性有:<span class=\"label primary\">间断性</span>、<span class=\"label primary\">失去封闭性</span>、<span class=\"label primary\">失去结果可再现性</span></li>\n<li>进程控制块的信息有:<span class=\"label primary\">进程标识符</span>、<span class=\"label primary\">处理机状态</span>、<span class=\"label primary\">进程控制信息</span>、<span class=\"label primary\">进程调度信息</span></li>\n<li>扇区是磁盘空间管理的最基本单位,其物理地址是由:<span class=\"label primary\">柱面号</span>、<span class=\"label primary\">扇区号</span>、<span class=\"label primary\">磁头号</span>三部分组成的</li>\n<li>火车站售票系统属于<span class=\"label primary\">实时系统</span></li>\n<li>I/O 管制程序的主要功能是管理<span class=\"label primary\">设备、控制器和通道</span>的状态信息</li>\n<li>依据信号量的发展过程,可将信号量分为四种:<span class=\"label primary\">and 型信号量</span>、<span class=\"label primary\">信号量集</span>、<span class=\"label primary\">互斥信号量</span> 以及 <span class=\"label primary\">整型信号量</span></li>\n<li>进程通信类型有:<span class=\"label primary\">共享存储器系统</span>、<span class=\"label primary\">消息传递系统</span>、<span class=\"label primary\">管道通信</span> 以及 <span class=\"label primary\">异步阻塞通信</span></li>\n<li>分段存储管理的优点有:<span class=\"label primary\">方便编程</span>、<span class=\"label primary\">信息共享</span>、<span class=\"label primary\">动态增长</span>、<span class=\"label primary\">动态链接</span>以及 <span class=\"label primary\">信息保护</span></li>\n<li><span class=\"label primary\">成批性</span>是批处理操作系统的主要特征,不是分时系统的特性</li>\n<li>推动操作系统发展的主要动力有:<span class=\"label primary\">不断提高计算机资源利用率</span>、<span class=\"label primary\">方便用户</span>、<span class=\"label primary\">器件的不断更新换代</span> 以及 <span class=\"label primary\">计算机体系结构的不断发展</span></li>\n<li>同步机制应当遵循的规则有:<span class=\"label primary\">空闲让进</span>、<span class=\"label primary\">让权等待</span>、<span class=\"label primary\">忙则等待</span> 以及 <span class=\"label primary\">有限等待</span></li>\n<li>系统中各个进程相互制约的关系称为<span class=\"label primary\">同步</span></li>\n<li>对于死锁,一般应考虑死锁的<span class=\"label primary\">预防</span>、<span class=\"label primary\">检测</span>、<span class=\"label primary\">避免</span> 以及 <span class=\"label primary\">解除</span></li>\n<li>典型的银行家算法是属于<span class=\"label primary\">死锁避免</span>,破坏环路等待条件是属于<span class=\"label primary\">死锁预防</span>,剥夺资源是属于<span class=\"label primary\">死锁解除</span></li>\n<li>操作系统向用户提供了两种接口分别是<span class=\"label primary\">用户接口</span>和<span class=\"label primary\">系统接口</span></li>\n<li>设别分别配应保证设备有<span class=\"label primary\">高利用率</span>和避免<span class=\"label primary\">死锁</span></li>\n<li>对于操作系统而言,打开文件广义指令的主要作用是装入<span class=\"label primary\">文件目录项</span></li>\n<li>为了实现多道程序设计,计算机在硬件方面必须提供两种支持,他们分别是<span class=\"label primary\">中断</span>和<span class=\"label primary\">通道</span></li>\n<li>多道程序设计给存储管理提出了新课题,应考虑的三个问题是<span class=\"label primary\">存储分配</span>、<span class=\"label primary\">虚存管理</span>、<span class=\"label primary\">存储保护</span></li>\n<li>操作系统的内核应提供<span class=\"label primary\">终端管理</span>、<span class=\"label primary\">短程管理</span>、<span class=\"label primary\">原语管理</span>三方面的功能</li>\n<li>死锁产生的主要原因为<span class=\"label primary\">资源竞争</span>和<span class=\"label primary\">进程非法推进</span></li>\n<li>设备分配外部设备时。先分配<span class=\"label primary\">设备</span>,再分配<span class=\"label primary\">控制器</span>,再分配<span class=\"label primary\">通道</span></li>\n<li>可用于文件系统管理空闲磁盘块的数据结构是<span class=\"label primary\">位示图</span>、<span class=\"label primary\">空闲盘块链</span>、<span class=\"label primary\">文件分配表 FAT</span></li>\n<li><span class=\"label primary\">索引文件</span>既利于文件的动态增长,也适合随机访问。</li>\n<li><span class=\"label primary\">Peterson 算法</span>实现互斥访问,<span class=\"label primary\">swap 指令</span>与<span class=\"label primary\"> TestAndSet 指令</span>实现忙则等待,<span class=\"label primary\">信号量算法</span>实现让权等待,<span class=\"label primary\">自旋锁</span>实现空闲让进</li>\n<li>银行家算法破坏了死锁四个必要条件的<span class=\"label primary\">循环等待条件</span></li>\n<li>死锁的四个条件为:<span class=\"label primary\">互斥条件</span>、<span class=\"label primary\">请求与保持条件</span>、<span class=\"label primary\">不可剥夺条件</span> 以及 <span class=\"label primary\">循环等待条件</span></li>\n<li></li>\n</ol>\n<h1 id=\"常用公式速记\"><a class=\"markdownIt-Anchor\" href=\"#常用公式速记\">#</a> 常用公式速记</h1>\n<h2 id=\"进程调度有关公式\"><a class=\"markdownIt-Anchor\" href=\"#进程调度有关公式\">#</a> 进程调度有关公式</h2>\n<p><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mtable rowspacing=\"0.15999999999999992em\" columnalign=\"center\" columnspacing=\"1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"false\"><mrow><msub><mi>T</mi><mtext>周转时间</mtext></msub><mo>=</mo><msub><mi>T</mi><mtext>结束时间</mtext></msub><mo>−</mo><msub><mi>T</mi><mtext>提交时间</mtext></msub></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\n\\begin {array}{c}\nT_{\\text{周转时间}}=T_{\\text{结束时间}}-T_{\\text{提交时间}}\n\\end {array}\n</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1.2000000000000002em;vertical-align:-0.35000000000000003em;\"></span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width:0.5em;\"></span><span class=\"col-align-c\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8500000000000001em;\"><span style=\"top:-3.01em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"mord\"><span class=\"mord\"><span class=\"mord mathnormal\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.32833099999999993em;\"><span style=\"top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">周转时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em;\"><span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mord\"><span class=\"mord mathnormal\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.32833099999999993em;\"><span style=\"top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">结束时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em;\"><span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2222222222222222em;\"></span><span class=\"mbin\">−</span><span class=\"mspace\" style=\"margin-right:0.2222222222222222em;\"></span><span class=\"mord\"><span class=\"mord mathnormal\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.32833099999999993em;\"><span style=\"top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">提交时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em;\"><span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.35000000000000003em;\"><span></span></span></span></span></span><span class=\"arraycolsep\" style=\"width:0.5em;\"></span></span></span></span></span></span></p>\n<p><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mtable rowspacing=\"0.15999999999999992em\" columnalign=\"center\" columnspacing=\"1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"false\"><mrow><msub><mi>T</mi><mtext>带权周转时间</mtext></msub><mo>=</mo><mfrac><msub><mi>T</mi><mtext>周转时间</mtext></msub><msub><mi>T</mi><mtext>运行时间</mtext></msub></mfrac></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\n\\begin {array}{c}\nT_{\\text{带权周转时间}}=\\frac{T_{\\text{周转时间}}}{T_{\\text{运行时间}}}\n\\end {array}\n</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1.3339409999999998em;vertical-align:-0.4169704999999999em;\"></span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width:0.5em;\"></span><span class=\"col-align-c\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.9169704999999999em;\"><span style=\"top:-3.0283345em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"mord\"><span class=\"mord\"><span class=\"mord mathnormal\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.32833099999999993em;\"><span style=\"top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">带权周转时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em;\"><span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mord\"><span class=\"mopen nulldelimiter\"></span><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8886359999999999em;\"><span style=\"top:-2.6550000000000002em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3448em;\"><span style=\"top:-2.3567071428571427em;margin-left:-0.13889em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">运行时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.14329285714285717em;\"><span></span></span></span></span></span></span></span></span></span><span style=\"top:-3.23em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"frac-line\" style=\"border-bottom-width:0.04em;\"></span></span><span style=\"top:-3.410305em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3448em;\"><span style=\"top:-2.3567071428571427em;margin-left:-0.13889em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">周转时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.14329285714285717em;\"><span></span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.44530499999999995em;\"><span></span></span></span></span></span><span class=\"mclose nulldelimiter\"></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.4169704999999999em;\"><span></span></span></span></span></span><span class=\"arraycolsep\" style=\"width:0.5em;\"></span></span></span></span></span></span></p>\n<p><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mtable rowspacing=\"0.15999999999999992em\" columnalign=\"center\" columnspacing=\"1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"false\"><mrow><msub><mi>T</mi><mtext>平均周转时间</mtext></msub><mo>=</mo><mfrac><mrow><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></msubsup><msub><mi>T</mi><mrow><mi>i</mi><mtext>周转时间</mtext></mrow></msub></mrow><mi>n</mi></mfrac></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\n\\begin {array}{c}\nT_{\\text{平均周转时间}}=\\frac{\\sum_{i=1}^{n} {T_{i\\text{周转时间}}}}{n}\n\\end {array}\n</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1.420007em;vertical-align:-0.46000349999999995em;\"></span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width:0.5em;\"></span><span class=\"col-align-c\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.9600035em;\"><span style=\"top:-2.9600034999999996em;\"><span class=\"pstrut\" style=\"height:3.0600069999999997em;\"></span><span class=\"mord\"><span class=\"mord\"><span class=\"mord mathnormal\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.32833099999999993em;\"><span style=\"top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">平均周转时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em;\"><span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mord\"><span class=\"mopen nulldelimiter\"></span><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:1.060007em;\"><span style=\"top:-2.6550000000000002em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">n</span></span></span></span><span style=\"top:-3.23em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"frac-line\" style=\"border-bottom-width:0.04em;\"></span></span><span style=\"top:-3.5350070000000002em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mop mtight\"><span class=\"mop op-symbol small-op mtight\" style=\"position:relative;top:-0.0000050000000000050004em;\">∑</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.7385428571428572em;\"><span style=\"top:-2.1785614285714283em;margin-left:0em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">i</span><span class=\"mrel mtight\">=</span><span class=\"mord mtight\">1</span></span></span></span><span style=\"top:-2.931em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">n</span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.32143857142857146em;\"><span></span></span></span></span></span></span><span class=\"mspace mtight\" style=\"margin-right:0.19516666666666668em;\"></span><span class=\"mord mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3448em;\"><span style=\"top:-2.3567071428571427em;margin-left:-0.13889em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">i</span><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">周转时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.14329285714285717em;\"><span></span></span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.345em;\"><span></span></span></span></span></span><span class=\"mclose nulldelimiter\"></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.46000349999999995em;\"><span></span></span></span></span></span><span class=\"arraycolsep\" style=\"width:0.5em;\"></span></span></span></span></span></span></p>\n<p><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mtable rowspacing=\"0.15999999999999992em\" columnalign=\"center\" columnspacing=\"1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"false\"><mrow><msub><mi>T</mi><mtext>平均带权周转时间</mtext></msub><mo>=</mo><mfrac><mrow><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></msubsup><msub><mi>T</mi><mrow><mi>i</mi><mtext>带权周转时间</mtext></mrow></msub></mrow><mi>n</mi></mfrac></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\n\\begin {array}{c}\nT_{\\text{平均带权周转时间}}=\\frac{\\sum_{i=1}^{n} {T_{i\\text{带权周转时间}}}}{n}\n\\end {array}\n</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1.420007em;vertical-align:-0.46000349999999995em;\"></span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width:0.5em;\"></span><span class=\"col-align-c\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.9600035em;\"><span style=\"top:-2.9600034999999996em;\"><span class=\"pstrut\" style=\"height:3.0600069999999997em;\"></span><span class=\"mord\"><span class=\"mord\"><span class=\"mord mathnormal\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.32833099999999993em;\"><span style=\"top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">平均带权周转时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em;\"><span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mord\"><span class=\"mopen nulldelimiter\"></span><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:1.060007em;\"><span style=\"top:-2.6550000000000002em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">n</span></span></span></span><span style=\"top:-3.23em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"frac-line\" style=\"border-bottom-width:0.04em;\"></span></span><span style=\"top:-3.5350070000000002em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mop mtight\"><span class=\"mop op-symbol small-op mtight\" style=\"position:relative;top:-0.0000050000000000050004em;\">∑</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.7385428571428572em;\"><span style=\"top:-2.1785614285714283em;margin-left:0em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">i</span><span class=\"mrel mtight\">=</span><span class=\"mord mtight\">1</span></span></span></span><span style=\"top:-2.931em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">n</span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.32143857142857146em;\"><span></span></span></span></span></span></span><span class=\"mspace mtight\" style=\"margin-right:0.19516666666666668em;\"></span><span class=\"mord mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3448em;\"><span style=\"top:-2.3567071428571427em;margin-left:-0.13889em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\">i</span><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">带权周转时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.14329285714285717em;\"><span></span></span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.345em;\"><span></span></span></span></span></span><span class=\"mclose nulldelimiter\"></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.46000349999999995em;\"><span></span></span></span></span></span><span class=\"arraycolsep\" style=\"width:0.5em;\"></span></span></span></span></span></span></p>\n<p><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mtable rowspacing=\"0.15999999999999992em\" columnalign=\"center\" columnspacing=\"1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"false\"><mrow><msub><mi>R</mi><mtext>响应比</mtext></msub><mo>=</mo><mfrac><msub><mi>T</mi><mtext>当前周转时间</mtext></msub><msub><mi>T</mi><mtext>运行时间</mtext></msub></mfrac><mo>=</mo><mfrac><msub><mi>T</mi><mtext>当前等待时间</mtext></msub><msub><mi>T</mi><mtext>运行时间</mtext></msub></mfrac><mo>+</mo><mn>1</mn></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\n\\begin {array}{c}\nR_{\\text{响应比}}=\\frac{T_{\\text{当前周转时间}}}{T_{\\text{运行时间}}}=\\frac{T_{\\text{当前等待时间}}}{T_{\\text{运行时间}}}+1\n\\end {array}\n</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1.3339409999999998em;vertical-align:-0.4169704999999999em;\"></span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width:0.5em;\"></span><span class=\"col-align-c\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.9169704999999999em;\"><span style=\"top:-3.0283345em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"mord\"><span class=\"mord\"><span class=\"mord mathnormal\" style=\"margin-right:0.00773em;\">R</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.32833099999999993em;\"><span style=\"top:-2.5500000000000003em;margin-left:-0.00773em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">响应比</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em;\"><span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mord\"><span class=\"mopen nulldelimiter\"></span><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8886359999999999em;\"><span style=\"top:-2.6550000000000002em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3448em;\"><span style=\"top:-2.3567071428571427em;margin-left:-0.13889em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">运行时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.14329285714285717em;\"><span></span></span></span></span></span></span></span></span></span><span style=\"top:-3.23em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"frac-line\" style=\"border-bottom-width:0.04em;\"></span></span><span style=\"top:-3.410305em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3448em;\"><span style=\"top:-2.3567071428571427em;margin-left:-0.13889em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">当前周转时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.14329285714285717em;\"><span></span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.44530499999999995em;\"><span></span></span></span></span></span><span class=\"mclose nulldelimiter\"></span></span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mord\"><span class=\"mopen nulldelimiter\"></span><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8886359999999999em;\"><span style=\"top:-2.6550000000000002em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3448em;\"><span style=\"top:-2.3567071428571427em;margin-left:-0.13889em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">运行时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.14329285714285717em;\"><span></span></span></span></span></span></span></span></span></span><span style=\"top:-3.23em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"frac-line\" style=\"border-bottom-width:0.04em;\"></span></span><span style=\"top:-3.410305em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\" style=\"margin-right:0.13889em;\">T</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3448em;\"><span style=\"top:-2.3567071428571427em;margin-left:-0.13889em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord text mtight\"><span class=\"mord cjk_fallback mtight\">当前等待时间</span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.14329285714285717em;\"><span></span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.44530499999999995em;\"><span></span></span></span></span></span><span class=\"mclose nulldelimiter\"></span></span><span class=\"mspace\" style=\"margin-right:0.2222222222222222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222222222222222em;\"></span><span class=\"mord\">1</span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.4169704999999999em;\"><span></span></span></span></span></span><span class=\"arraycolsep\" style=\"width:0.5em;\"></span></span></span></span></span></span></p>\n<h1 id=\"典型例题\"><a class=\"markdownIt-Anchor\" href=\"#典型例题\">#</a> 典型例题</h1>\n<h2 id=\"逻辑地址转物理地址\"><a class=\"markdownIt-Anchor\" href=\"#逻辑地址转物理地址\">#</a> 逻辑地址转物理地址</h2>\n<p>已知某分页系统,内存容量为 64KB,页面大小为 1KB,对一个 4 页大的作业,其 0、1、2、3 页分别被分配到内存的 2、4、6、7 块中。</p>\n<p>将十进制的逻辑地址 1023 变换为物理地址。</p>\n<p><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mtable rowspacing=\"0.15999999999999992em\" columnalign=\"center\" columnspacing=\"1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"false\"><mrow><mtext>内存容量</mtext><mn>64</mn><mi>K</mi><mi>B</mi><mtext>——</mtext><msup><mn>2</mn><mn>16</mn></msup></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\n\\begin {array}{c}\n内存容量64KB ——2^{16}\n\\end {array}\n</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1.2000000000000002em;vertical-align:-0.35000000000000003em;\"></span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width:0.5em;\"></span><span class=\"col-align-c\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8500000000000001em;\"><span style=\"top:-3.01em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"mord\"><span class=\"mord cjk_fallback\">内</span><span class=\"mord cjk_fallback\">存</span><span class=\"mord cjk_fallback\">容</span><span class=\"mord cjk_fallback\">量</span><span class=\"mord\">6</span><span class=\"mord\">4</span><span class=\"mord mathnormal\" style=\"margin-right:0.07153em;\">K</span><span class=\"mord mathnormal\" style=\"margin-right:0.05017em;\">B</span><span class=\"mord\">—</span><span class=\"mord\">—</span><span class=\"mord\"><span class=\"mord\">2</span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8141079999999999em;\"><span style=\"top:-3.063em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">1</span><span class=\"mord mtight\">6</span></span></span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.35000000000000003em;\"><span></span></span></span></span></span><span class=\"arraycolsep\" style=\"width:0.5em;\"></span></span></span></span></span></span></p>\n<p><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mtable rowspacing=\"0.15999999999999992em\" columnalign=\"center\" columnspacing=\"1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"false\"><mrow><mtext>页面大小为</mtext><mn>1</mn><mi>K</mi><mi>B</mi><mtext>——</mtext><msup><mn>2</mn><mn>10</mn></msup></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\n\\begin {array}{c}\n页面大小为1KB——2^{10}\n\\end {array}\n</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1.2000000000000002em;vertical-align:-0.35000000000000003em;\"></span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width:0.5em;\"></span><span class=\"col-align-c\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8500000000000001em;\"><span style=\"top:-3.01em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"mord\"><span class=\"mord cjk_fallback\">页</span><span class=\"mord cjk_fallback\">面</span><span class=\"mord cjk_fallback\">大</span><span class=\"mord cjk_fallback\">小</span><span class=\"mord cjk_fallback\">为</span><span class=\"mord\">1</span><span class=\"mord mathnormal\" style=\"margin-right:0.07153em;\">K</span><span class=\"mord mathnormal\" style=\"margin-right:0.05017em;\">B</span><span class=\"mord\">—</span><span class=\"mord\">—</span><span class=\"mord\"><span class=\"mord\">2</span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8141079999999999em;\"><span style=\"top:-3.063em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">1</span><span class=\"mord mtight\">0</span></span></span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.35000000000000003em;\"><span></span></span></span></span></span><span class=\"arraycolsep\" style=\"width:0.5em;\"></span></span></span></span></span></span></p>\n<p><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mtable rowspacing=\"0.15999999999999992em\" columnalign=\"center\" columnspacing=\"1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"false\"><mrow><mtext>共有</mtext><mfrac><msup><mn>2</mn><mn>16</mn></msup><msup><mn>2</mn><mn>10</mn></msup></mfrac><mo>=</mo><msup><mn>2</mn><mn>6</mn></msup><mtext>页</mtext></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\n\\begin {array}{c}\n共有\\frac{2^{16}}{2^{10}} =2^{6}页\n\\end {array}\n</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1.37792em;vertical-align:-0.43895999999999996em;\"></span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width:0.5em;\"></span><span class=\"col-align-c\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.93896em;\"><span style=\"top:-2.9389600000000002em;\"><span class=\"pstrut\" style=\"height:3.01792em;\"></span><span class=\"mord\"><span class=\"mord cjk_fallback\">共</span><span class=\"mord cjk_fallback\">有</span><span class=\"mord\"><span class=\"mopen nulldelimiter\"></span><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:1.01792em;\"><span style=\"top:-2.6550000000000002em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">2</span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.7463142857142857em;\"><span style=\"top:-2.786em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">1</span><span class=\"mord mtight\">0</span></span></span></span></span></span></span></span></span></span></span></span><span style=\"top:-3.23em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"frac-line\" style=\"border-bottom-width:0.04em;\"></span></span><span style=\"top:-3.394em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">2</span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8913142857142857em;\"><span style=\"top:-2.931em;margin-right:0.07142857142857144em;\"><span class=\"pstrut\" style=\"height:2.5em;\"></span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">1</span><span class=\"mord mtight\">6</span></span></span></span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.345em;\"><span></span></span></span></span></span><span class=\"mclose nulldelimiter\"></span></span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mord\"><span class=\"mord\">2</span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8141079999999999em;\"><span style=\"top:-3.063em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">6</span></span></span></span></span></span></span></span></span><span class=\"mord cjk_fallback\">页</span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.43895999999999996em;\"><span></span></span></span></span></span><span class=\"arraycolsep\" style=\"width:0.5em;\"></span></span></span></span></span></span></p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">页</th>\n<th style=\"text-align:center\">块</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\"><ins><strong>0</strong></ins></td>\n<td style=\"text-align:center\"><ins><strong>2</strong></ins></td>\n</tr>\n<tr>\n<td style=\"text-align:center\">1</td>\n<td style=\"text-align:center\">4</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">2</td>\n<td style=\"text-align:center\">6</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">3</td>\n<td style=\"text-align:center\">7</td>\n</tr>\n</tbody>\n</table>\n<p><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mtable rowspacing=\"0.15999999999999992em\" columnalign=\"center\" columnspacing=\"1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"false\"><mrow><mn>102</mn><msub><mn>3</mn><mrow><mo stretchy=\"false\">(</mo><mn>10</mn><mo stretchy=\"false\">)</mo></mrow></msub><mo>=</mo><mn>00111111111</mn><msub><mn>1</mn><mrow><mo stretchy=\"false\">(</mo><mn>2</mn><mo stretchy=\"false\">)</mo></mrow></msub></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\n\\begin {array}{c}\n1023_{(10)} =0011 1111 1111_{(2)}\n\\end {array}\n</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1.2000000000000002em;vertical-align:-0.35000000000000003em;\"></span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width:0.5em;\"></span><span class=\"col-align-c\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8500000000000001em;\"><span style=\"top:-3.01em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"mord\"><span class=\"mord\">1</span><span class=\"mord\">0</span><span class=\"mord\">2</span><span class=\"mord\"><span class=\"mord\">3</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.34480000000000005em;\"><span style=\"top:-2.5198em;margin-left:0em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mopen mtight\">(</span><span class=\"mord mtight\">1</span><span class=\"mord mtight\">0</span><span class=\"mclose mtight\">)</span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3551999999999999em;\"><span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mord\">0</span><span class=\"mord\">0</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\"><span class=\"mord\">1</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.34480000000000005em;\"><span style=\"top:-2.5198em;margin-left:0em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mopen mtight\">(</span><span class=\"mord mtight\">2</span><span class=\"mclose mtight\">)</span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3551999999999999em;\"><span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.35000000000000003em;\"><span></span></span></span></span></span><span class=\"arraycolsep\" style=\"width:0.5em;\"></span></span></span></span></span></span><br>\n<span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mtable rowspacing=\"0.15999999999999992em\" columnalign=\"center\" columnspacing=\"1em\"><mtr><mtd><mstyle scriptlevel=\"0\" displaystyle=\"false\"><mrow><mtext>转换后</mtext><mn>10111111111</mn><msub><mn>1</mn><mrow><mo stretchy=\"false\">(</mo><mn>2</mn><mo stretchy=\"false\">)</mo></mrow></msub><mo>=</mo><mn>3</mn><mo separator=\"true\">,</mo><mn>07</mn><msub><mn>1</mn><mrow><mo stretchy=\"false\">(</mo><mn>10</mn><mo stretchy=\"false\">)</mo></mrow></msub></mrow></mstyle></mtd></mtr></mtable><annotation encoding=\"application/x-tex\">\n\\begin {array}{c}\n转换后 1011 1111 1111_{(2)}=3,071_{(10)}\n\\end {array}\n</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1.2000000000000002em;vertical-align:-0.35000000000000003em;\"></span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width:0.5em;\"></span><span class=\"col-align-c\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8500000000000001em;\"><span style=\"top:-3.01em;\"><span class=\"pstrut\" style=\"height:3em;\"></span><span class=\"mord\"><span class=\"mord cjk_fallback\">转</span><span class=\"mord cjk_fallback\">换</span><span class=\"mord cjk_fallback\">后</span><span class=\"mord\">1</span><span class=\"mord\">0</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\">1</span><span class=\"mord\"><span class=\"mord\">1</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.34480000000000005em;\"><span style=\"top:-2.5198em;margin-left:0em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mopen mtight\">(</span><span class=\"mord mtight\">2</span><span class=\"mclose mtight\">)</span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3551999999999999em;\"><span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2777777777777778em;\"></span><span class=\"mord\">3</span><span class=\"mpunct\">,</span><span class=\"mspace\" style=\"margin-right:0.16666666666666666em;\"></span><span class=\"mord\">0</span><span class=\"mord\">7</span><span class=\"mord\"><span class=\"mord\">1</span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.34480000000000005em;\"><span style=\"top:-2.5198em;margin-left:0em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mopen mtight\">(</span><span class=\"mord mtight\">1</span><span class=\"mord mtight\">0</span><span class=\"mclose mtight\">)</span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3551999999999999em;\"><span></span></span></span></span></span></span></span></span></span><span class=\"vlist-s\"></span></span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.35000000000000003em;\"><span></span></span></span></span></span><span class=\"arraycolsep\" style=\"width:0.5em;\"></span></span></span></span></span></span></p>\n",
"tags": [
"操作系统",
"OS"
]
},
{
"id": "https://735690757.github.io/DSLearnNote/GeneralizedLists/",
"url": "https://735690757.github.io/DSLearnNote/GeneralizedLists/",
"title": "考试中有关广义表的两个常用函数的解",
"date_published": "2024-09-09T03:00:00.000Z",
"content_html": "<h1 id=\"认识广义表\"><a class=\"markdownIt-Anchor\" href=\"#认识广义表\">#</a> 认识广义表</h1>\n<p>广义表是线性表的推广,与线性表不同的是,线性表中的每一个数据元素都属于同一数据对象。</p>\n<p>广义表可以表示为:</p>\n<ol>\n<li>空表:()</li>\n<li>表头:(表头)</li>\n<li>表头 + 表尾:(表头,表尾)</li>\n</ol>\n<p><strong>实际上这就是他的基本结构,而对于其中的元素来说,它可以是表,也可以是元素,这就是广义!</strong></p>\n<h1 id=\"取头head\"><a class=\"markdownIt-Anchor\" href=\"#取头head\">#</a> 取头 Head ()</h1>\n<p>Head 是取头操作,他拿的是一个<strong>元素</strong>或者一个<strong>表</strong></p>\n<h1 id=\"取尾tail\"><a class=\"markdownIt-Anchor\" href=\"#取尾tail\">#</a> 取尾 Tail ()</h1>\n<p>Tail 是取尾操作,他拿到的必是一个<strong>表</strong></p>\n<h1 id=\"巧记\"><a class=\"markdownIt-Anchor\" href=\"#巧记\">#</a> 巧记</h1>\n<p>对于蟒蛇(Python)来说,头只有一个,而它的尾巴很长。</p>\n<p>所以,取头<strong> Head</strong> 元素比<strong>较单一</strong>,取尾<strong> Tail</strong> 往往<strong>比较长</strong>。</p>\n<h1 id=\"练习\"><a class=\"markdownIt-Anchor\" href=\"#练习\">#</a> 练习</h1>\n<div class=\"note primary\">\n<p>A=(a,b)</p>\n<p>B=(A,A)</p>\n<p>C=(a,(b,A),B)</p>\n<p>对于操作:Tail(Head(Tail(C)))的结果是什么?</p>\n</div>\n<h1 id=\"解答\"><a class=\"markdownIt-Anchor\" href=\"#解答\">#</a> 解答</h1>\n<p>Tail(C)尾巴长:(a,<ins class=\"dot warning\">(b,A),B</ins> )</p>\n<p><span class=\"label info\">Tail(C)=((b,A),B)</span></p>\n<p>Head(Tail(C))头短:(<ins class=\"dot warning\">(b,A)</ins>,B)</p>\n<p><span class=\"label info\">Head(Tail(C))=(b,A)</span></p>\n<p>Tail(Head(Tail(C)))尾巴长:(b,<ins class=\"dot warning\">A</ins>)</p>\n<p><span class=\"label info\">Tail(Head(Tail(C)))=(A)</span></p>\n<p><strong>尾巴长必是一个表,头短可能是一个表也可能是一个元素</strong></p>\n",
"tags": [
"DS",
"数据结构"
]
},
{
"id": "https://735690757.github.io/Operate-system/kcsj/",
"url": "https://735690757.github.io/Operate-system/kcsj/",
"title": "操作系统课程设计",
"date_published": "2024-01-04T07:41:00.000Z",
"content_html": "<h1 id=\"虚拟存储器管理\"><a class=\"markdownIt-Anchor\" href=\"#虚拟存储器管理\">#</a> 虚拟存储器管理</h1>\n<iframe src=\"//player.bilibili.com/player.html?aid=793352357&bvid=BV1KC4y1v7JM&cid=1393861516&p=1\" width=\"788px\" height=\"443px\" scrolling=\"yes\" border=\"0\" frameborder=\"no\" framespacing=\"10\" allowfullscreen=\"true\"> </iframe>\n<h2 id=\"什么是虚拟存储器\"><a class=\"markdownIt-Anchor\" href=\"#什么是虚拟存储器\">#</a> 什么是虚拟存储器?</h2>\n<p> 虚拟存储器是一种计算机内存管理技术,它通过将计算机的硬盘空间作为辅助存储器,允许程序使用比物理内存更大的地址空间。虚拟存储器的目标是提供更大的可用内存空间,以便同时运行更多的程序,而不受物理内存的限制。</p>\n<p> 虚拟存储的实现是基于局部存储原理的,要理解虚拟存储我们就要去理解局部存储的是实现,即:分页存储、分段存储、段页式存储。</p>\n<p><strong>(这里我们重点掌握具有块表的分页存储)</strong></p>\n<h2 id=\"课程设计核心目的\"><a class=\"markdownIt-Anchor\" href=\"#课程设计核心目的\">#</a> 课程设计核心目的?</h2>\n<p><ins class=\"wavy\">将逻辑地址转为物理地址</ins></p>\n<h1 id=\"页表\"><a class=\"markdownIt-Anchor\" href=\"#页表\">#</a> 页表?</h1>\n<table>\n<thead>\n<tr>\n<th><strong>页号</strong></th>\n<th><strong>块号</strong></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>0</td>\n<td>0</td>\n</tr>\n<tr>\n<td>1</td>\n<td>2</td>\n</tr>\n<tr>\n<td>2</td>\n<td>4</td>\n</tr>\n<tr>\n<td>3</td>\n<td>6</td>\n</tr>\n</tbody>\n</table>\n<p>针对这个课程设计,我们简单的理解为应用页表就是通过页号,来去找到块号</p>\n<p><a href=\"https://imgse.com/i/pivXrrt\"><img data-src=\"https://s11.ax1x.com/2024/01/04/pivXrrt.png\" alt=\"地址转换\" style=\"zoom: 67%;\" /></a></p>\n<p>由虚拟地址(逻辑地址)转换为物理地址,这就是页表最核心的作用!</p>\n<h1 id=\"为什么要用虚拟内存\"><a class=\"markdownIt-Anchor\" href=\"#为什么要用虚拟内存\">#</a> 为什么要用虚拟内存</h1>\n<p>但是,我们的内存很小,还想运行多个应用程序,这必然无法满足所有的有的应用程序一次性全部加载到内存之中。根据局部性理论基础,我们又引申出页面的对换算法(页面置换算法)。</p>\n<p>本次课程设计采用的是 Clock 算法</p>\n<p>将页表扩充,引入访问位、修改位、有效位(本次仅用于算法实现,它其实用其他</p>\n<p>更有用的功能,在此不做介绍)</p>\n<table>\n<thead>\n<tr>\n<th><strong>修改位</strong></th>\n<th><strong>访问位</strong></th>\n<th><strong>重要排名</strong></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>0</td>\n<td>0</td>\n<td>4</td>\n</tr>\n<tr>\n<td>0</td>\n<td>1</td>\n<td>3</td>\n</tr>\n<tr>\n<td>1</td>\n<td>0</td>\n<td>2</td>\n</tr>\n<tr>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n<p>在置换时,优先考虑不那么重要的(排名越低越不重要),对于不重要的页优先换出</p>\n<h1 id=\"状态转换\"><a class=\"markdownIt-Anchor\" href=\"#状态转换\">#</a> 状态转换?</h1>\n<p>这里稍后同步,大家可以先看视频里的有关状态转换的图。</p>\n<h1 id=\"代码实现\"><a class=\"markdownIt-Anchor\" href=\"#代码实现\">#</a> 代码实现</h1>\n<figure class=\"highlight cpp\"><figcaption data-lang=\"C++\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"2\"></td><td><pre> * @Author KarryLiu</pre></td></tr><tr><td data-num=\"3\"></td><td><pre> * @Creed may all the beauty be blessed</pre></td></tr><tr><td data-num=\"4\"></td><td><pre> * @Date 2023/12/4 上午 10:04</pre></td></tr><tr><td data-num=\"5\"></td><td><pre> * @Description TODO 诗岸梦行舟</pre></td></tr><tr><td data-num=\"6\"></td><td><pre> * @Version 1.0</pre></td></tr><tr><td data-num=\"7\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">include</span> <span class=\"token string\"><limits></span></span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">include</span> <span class=\"token string\">\"iostream\"</span></span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre><span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">include</span> <span class=\"token string\">\"windows.h\"</span></span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre><span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">include</span> <span class=\"token string\">\"unistd.h\"</span></span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre></pre></td></tr><tr><td data-num=\"13\"></td><td><pre><span class=\"token comment\">// 颜色枚举,为了好看</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre><span class=\"token keyword\">enum</span> <span class=\"token class-name\">ConsoleColor</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> Black <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> Blue <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> Green <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> Cyan <span class=\"token operator\">=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> Red <span class=\"token operator\">=</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> Magenta <span class=\"token operator\">=</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> Yellow <span class=\"token operator\">=</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> White <span class=\"token operator\">=</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> Gray <span class=\"token operator\">=</span> <span class=\"token number\">8</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre></pre></td></tr><tr><td data-num=\"26\"></td><td><pre><span class=\"token comment\">// 设置文本颜色函数</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>ConsoleColor text<span class=\"token punctuation\">,</span> ConsoleColor background<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token keyword\">int</span> color <span class=\"token operator\">=</span> text <span class=\"token operator\">+</span> background <span class=\"token operator\">*</span> <span class=\"token number\">16</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token function\">SetConsoleTextAttribute</span><span class=\"token punctuation\">(</span><span class=\"token function\">GetStdHandle</span><span class=\"token punctuation\">(</span>STD_OUTPUT_HANDLE<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> color<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre><span class=\"token comment\">// 块大小</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre><span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">define</span> <span class=\"token macro-name\">blockSize</span> <span class=\"token expression\"><span class=\"token number\">4</span></span></span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre><span class=\"token comment\">// 页大小</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre><span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">define</span> <span class=\"token macro-name\">pageSize</span> <span class=\"token expression\"><span class=\"token number\">2</span></span></span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre><span class=\"token comment\">// 快表尺寸</span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre><span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">define</span> <span class=\"token macro-name\">fastTableDimensions</span> <span class=\"token expression\"><span class=\"token number\">4</span></span></span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre><span class=\"token comment\">// 页表尺寸</span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre><span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">define</span> <span class=\"token macro-name\">pageTableDimensions</span> <span class=\"token expression\"><span class=\"token number\">6</span></span></span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre><span class=\"token comment\">// 程序最大逻辑地址</span></pre></td></tr><tr><td data-num=\"40\"></td><td><pre><span class=\"token keyword\">const</span> <span class=\"token keyword\">int</span> logicalMaxAddress <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"41\"></td><td><pre><span class=\"token comment\">// 逻辑地址数据结构 -> 页</span></pre></td></tr><tr><td data-num=\"42\"></td><td><pre><span class=\"token keyword\">struct</span> <span class=\"token class-name\">logicalAddressDataStruct</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"43\"></td><td><pre> <span class=\"token keyword\">int</span> pageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"44\"></td><td><pre> <span class=\"token keyword\">int</span> inPageAddress<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"45\"></td><td><pre><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"46\"></td><td><pre><span class=\"token comment\">// 页逻辑地址实现机构</span></pre></td></tr><tr><td data-num=\"47\"></td><td><pre>logicalAddressDataStruct logicalAddress<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"48\"></td><td><pre><span class=\"token comment\">// 模拟外存中单条数据的数据结构</span></pre></td></tr><tr><td data-num=\"49\"></td><td><pre><span class=\"token keyword\">struct</span> <span class=\"token class-name\">externalMemoryDataStruct</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"50\"></td><td><pre> <span class=\"token keyword\">int</span> externalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"51\"></td><td><pre> <span class=\"token keyword\">int</span> externalBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"52\"></td><td><pre> <span class=\"token comment\">// 访问位</span></pre></td></tr><tr><td data-num=\"53\"></td><td><pre> <span class=\"token keyword\">bool</span> accessBit<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"54\"></td><td><pre> <span class=\"token comment\">// 修改位</span></pre></td></tr><tr><td data-num=\"55\"></td><td><pre> <span class=\"token keyword\">bool</span> modifyBit<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"56\"></td><td><pre> <span class=\"token comment\">// 有效位</span></pre></td></tr><tr><td data-num=\"57\"></td><td><pre> <span class=\"token keyword\">bool</span> validBit<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"58\"></td><td><pre><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"59\"></td><td><pre></pre></td></tr><tr><td data-num=\"60\"></td><td><pre><span class=\"token comment\">// 外存所有存储结构,也就是最大逻辑地址 100 的一半,50 页</span></pre></td></tr><tr><td data-num=\"61\"></td><td><pre>externalMemoryDataStruct externalMemory<span class=\"token punctuation\">[</span>logicalMaxAddress <span class=\"token operator\">/</span> pageSize<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"62\"></td><td><pre><span class=\"token comment\">// 模拟内存中单条数据的数据结构 (页表)</span></pre></td></tr><tr><td data-num=\"63\"></td><td><pre><span class=\"token keyword\">struct</span> <span class=\"token class-name\">internalStorageDataStruct</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"64\"></td><td><pre> <span class=\"token keyword\">int</span> internalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"65\"></td><td><pre> <span class=\"token keyword\">int</span> internalBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"66\"></td><td><pre> <span class=\"token comment\">// 访问位</span></pre></td></tr><tr><td data-num=\"67\"></td><td><pre> <span class=\"token keyword\">bool</span> accessBit<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"68\"></td><td><pre> <span class=\"token comment\">// 修改位</span></pre></td></tr><tr><td data-num=\"69\"></td><td><pre> <span class=\"token keyword\">bool</span> modifyBit<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"70\"></td><td><pre> <span class=\"token comment\">// 有效位</span></pre></td></tr><tr><td data-num=\"71\"></td><td><pre> <span class=\"token keyword\">bool</span> validBit<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"72\"></td><td><pre><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"73\"></td><td><pre><span class=\"token comment\">// 页表实体</span></pre></td></tr><tr><td data-num=\"74\"></td><td><pre>internalStorageDataStruct pageTable<span class=\"token punctuation\">[</span>pageTableDimensions<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"75\"></td><td><pre><span class=\"token comment\">// 快表数据结构</span></pre></td></tr><tr><td data-num=\"76\"></td><td><pre><span class=\"token keyword\">struct</span> <span class=\"token class-name\">fastTableDataStruct</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"77\"></td><td><pre> <span class=\"token keyword\">int</span> fastTablePageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"78\"></td><td><pre> <span class=\"token keyword\">int</span> fastTableBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"79\"></td><td><pre> <span class=\"token comment\">// 访问位</span></pre></td></tr><tr><td data-num=\"80\"></td><td><pre> <span class=\"token keyword\">bool</span> accessBit<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"81\"></td><td><pre> <span class=\"token comment\">// 修改位</span></pre></td></tr><tr><td data-num=\"82\"></td><td><pre> <span class=\"token keyword\">bool</span> modifyBit<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"83\"></td><td><pre> <span class=\"token comment\">// 有效位</span></pre></td></tr><tr><td data-num=\"84\"></td><td><pre> <span class=\"token keyword\">bool</span> validBit<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"85\"></td><td><pre><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"86\"></td><td><pre><span class=\"token comment\">// 快表实体</span></pre></td></tr><tr><td data-num=\"87\"></td><td><pre>fastTableDataStruct fastTable<span class=\"token punctuation\">[</span>fastTableDimensions<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"88\"></td><td><pre><span class=\"token comment\">// 快表置换排行榜数据结构</span></pre></td></tr><tr><td data-num=\"89\"></td><td><pre><span class=\"token keyword\">struct</span> <span class=\"token class-name\">rankForFastTableDataStruct</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"90\"></td><td><pre> <span class=\"token keyword\">int</span> pageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"91\"></td><td><pre> <span class=\"token keyword\">int</span> fastTableIndex<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"92\"></td><td><pre><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"93\"></td><td><pre><span class=\"token comment\">// 页表置换排行榜数据结构</span></pre></td></tr><tr><td data-num=\"94\"></td><td><pre><span class=\"token keyword\">struct</span> <span class=\"token class-name\">rankForPageTableDataStruct</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"95\"></td><td><pre> <span class=\"token keyword\">int</span> pageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"96\"></td><td><pre> <span class=\"token keyword\">int</span> pageTableIndex<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"97\"></td><td><pre><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"98\"></td><td><pre><span class=\"token comment\">// 物理地址数据结构</span></pre></td></tr><tr><td data-num=\"99\"></td><td><pre><span class=\"token keyword\">struct</span> <span class=\"token class-name\">physicalAddressDataStruct</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"100\"></td><td><pre> <span class=\"token keyword\">int</span> blockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"101\"></td><td><pre> <span class=\"token keyword\">int</span> internalBlockAddress<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"102\"></td><td><pre><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"103\"></td><td><pre><span class=\"token comment\">// 转换后的物理地址实体</span></pre></td></tr><tr><td data-num=\"104\"></td><td><pre>physicalAddressDataStruct physicalAddress<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"105\"></td><td><pre><span class=\"token keyword\">using</span> <span class=\"token keyword\">namespace</span> std<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"106\"></td><td><pre></pre></td></tr><tr><td data-num=\"107\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"108\"></td><td><pre> * @Describe 初始化外存数据</pre></td></tr><tr><td data-num=\"109\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"110\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">InitializeExternalData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"111\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> logicalMaxAddress <span class=\"token operator\">/</span> pageSize<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"112\"></td><td><pre> <span class=\"token comment\">// 计算页号与块号</span></pre></td></tr><tr><td data-num=\"113\"></td><td><pre> externalMemory<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>externalPageNumber <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"114\"></td><td><pre> externalMemory<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>externalBlockNumber <span class=\"token operator\">=</span> i <span class=\"token operator\">/</span> blockSize<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"115\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"116\"></td><td><pre><span class=\"token comment\">// for (int i = 0; i < logicalMaxAddress / pageSize; ++i) {</span></pre></td></tr><tr><td data-num=\"117\"></td><td><pre><span class=\"token comment\">// cout<<externalMemory[i].externalPageNumber<<\" \"<<externalMemory[i].externalBlockNumber<<endl;</span></pre></td></tr><tr><td data-num=\"118\"></td><td><pre><span class=\"token comment\">// }</span></pre></td></tr><tr><td data-num=\"119\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"120\"></td><td><pre></pre></td></tr><tr><td data-num=\"121\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"122\"></td><td><pre> * @Describe 从外存中寻找所缺失的页</pre></td></tr><tr><td data-num=\"123\"></td><td><pre> * @return externalMemoryDataStruct 返回找到的外存数据页</pre></td></tr><tr><td data-num=\"124\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"125\"></td><td><pre>externalMemoryDataStruct <span class=\"token function\">LookMissingPageFromExternalMemory</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> logicalAddressPageNumber<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"126\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> logicalMaxAddress <span class=\"token operator\">/</span> pageSize<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"127\"></td><td><pre> <span class=\"token comment\">// 计算页号与块号</span></pre></td></tr><tr><td data-num=\"128\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>externalMemory<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>externalPageNumber <span class=\"token operator\">==</span> logicalAddressPageNumber<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"129\"></td><td><pre> <span class=\"token keyword\">return</span> externalMemory<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"130\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"131\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"132\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"133\"></td><td><pre></pre></td></tr><tr><td data-num=\"134\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">PageTableVisualization</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"135\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Magenta<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"136\"></td><td><pre></pre></td></tr><tr><td data-num=\"137\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"-------------------页表(内存)-------------------+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"138\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> pageTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"139\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"页号:\"</span> <span class=\"token operator\"><<</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber <span class=\"token operator\"><<</span> <span class=\"token string\">\" 块号:\"</span> <span class=\"token operator\"><<</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalBlockNumber <span class=\"token operator\"><<</span> <span class=\"token string\">\" 访问位:\"</span></pre></td></tr><tr><td data-num=\"140\"></td><td><pre> <span class=\"token operator\"><<</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\"><<</span> <span class=\"token string\">\" 修改位:\"</span> <span class=\"token operator\"><<</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\"><<</span> <span class=\"token string\">\" 有效位:\"</span> <span class=\"token operator\"><<</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"141\"></td><td><pre> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"142\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"143\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"--------------------------------------------------+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"144\"></td><td><pre></pre></td></tr><tr><td data-num=\"145\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"146\"></td><td><pre></pre></td></tr><tr><td data-num=\"147\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">FastTableVisualization</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"148\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Cyan<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"149\"></td><td><pre><span class=\"token comment\">// sleep(1);</span></pre></td></tr><tr><td data-num=\"150\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"----------------------快表-----------------------+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"151\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> fastTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"152\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"页号:\"</span> <span class=\"token operator\"><<</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber <span class=\"token operator\"><<</span> <span class=\"token string\">\" 块号:\"</span> <span class=\"token operator\"><<</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableBlockNumber</pre></td></tr><tr><td data-num=\"153\"></td><td><pre> <span class=\"token operator\"><<</span> <span class=\"token string\">\" 访问位:\"</span> <span class=\"token operator\"><<</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\"><<</span> <span class=\"token string\">\" 修改位:\"</span> <span class=\"token operator\"><<</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\"><<</span> <span class=\"token string\">\" 有效位:\"</span></pre></td></tr><tr><td data-num=\"154\"></td><td><pre> <span class=\"token operator\"><<</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"155\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"156\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"-------------------------------------------------+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"157\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"158\"></td><td><pre></pre></td></tr><tr><td data-num=\"159\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"160\"></td><td><pre> * @Describe 初始化页表</pre></td></tr><tr><td data-num=\"161\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"162\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">InitializePageTable</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"163\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"164\"></td><td><pre></pre></td></tr><tr><td data-num=\"165\"></td><td><pre></pre></td></tr><tr><td data-num=\"166\"></td><td><pre><span class=\"token keyword\">int</span> <span class=\"token function\">main</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"167\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Cyan<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"168\"></td><td><pre> cout<span class=\"token operator\"><<</span><span class=\"token string\">\"诗岸梦行舟\"</span><span class=\"token operator\"><<</span>endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"169\"></td><td><pre> cout<span class=\"token operator\"><<</span><span class=\"token string\">\"操作系统课程设计:虚拟存储器管理\"</span><span class=\"token operator\"><<</span>endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"170\"></td><td><pre> <span class=\"token function\">sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"171\"></td><td><pre> <span class=\"token comment\">// 系统请求的逻辑地址</span></pre></td></tr><tr><td data-num=\"172\"></td><td><pre> <span class=\"token keyword\">int</span> requestLogicalAddressByOS <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"173\"></td><td><pre> <span class=\"token comment\">// 初始化外存数据结构</span></pre></td></tr><tr><td data-num=\"174\"></td><td><pre> <span class=\"token function\">InitializeExternalData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"175\"></td><td><pre> <span class=\"token comment\">// 快表发现位,真就是发现了,假就是没发现</span></pre></td></tr><tr><td data-num=\"176\"></td><td><pre> <span class=\"token keyword\">bool</span> fastTableFind <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"177\"></td><td><pre> <span class=\"token comment\">// 在快表的哪一位发现的?</span></pre></td></tr><tr><td data-num=\"178\"></td><td><pre> <span class=\"token keyword\">int</span> fastTableFindPoint<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"179\"></td><td><pre> <span class=\"token comment\">// 页表发现位,真就是发现了,假就是没发现</span></pre></td></tr><tr><td data-num=\"180\"></td><td><pre> <span class=\"token keyword\">bool</span> pageTableFind <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"181\"></td><td><pre> <span class=\"token comment\">// 在页表的哪一位发现的?</span></pre></td></tr><tr><td data-num=\"182\"></td><td><pre> <span class=\"token keyword\">int</span> pageTableFindPoint<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"183\"></td><td><pre> <span class=\"token comment\">// 当前内存容量(页表剩余容量)</span></pre></td></tr><tr><td data-num=\"184\"></td><td><pre> <span class=\"token keyword\">int</span> remainingCapacityOfPageTable <span class=\"token operator\">=</span> <span class=\"token number\">6</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"185\"></td><td><pre> <span class=\"token comment\">// 当前快表容量(快表剩余容量)</span></pre></td></tr><tr><td data-num=\"186\"></td><td><pre> <span class=\"token keyword\">int</span> remainingCapacityOfFastTable <span class=\"token operator\">=</span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"187\"></td><td><pre></pre></td></tr><tr><td data-num=\"188\"></td><td><pre></pre></td></tr><tr><td data-num=\"189\"></td><td><pre> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"190\"></td><td><pre> <span class=\"token comment\">// 初始化物理地址数据暂存</span></pre></td></tr><tr><td data-num=\"191\"></td><td><pre> physicalAddress<span class=\"token punctuation\">.</span>blockNumber <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"192\"></td><td><pre> physicalAddress<span class=\"token punctuation\">.</span>internalBlockAddress <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"193\"></td><td><pre></pre></td></tr><tr><td data-num=\"194\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Blue<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"195\"></td><td><pre><span class=\"token comment\">// sleep(2);</span></pre></td></tr><tr><td data-num=\"196\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"系统基本信息:\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"197\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\" +------------------------+\"</span> <span class=\"token operator\"><<</span><span class=\"token string\">\"----------------------+\"</span><span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"198\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\" | 块大小:\"</span> <span class=\"token operator\"><<</span> blockSize <span class=\"token operator\"><<</span> <span class=\"token string\">\" |\"</span> <span class=\"token operator\"><<</span><span class=\"token string\">\" xx大学 |\"</span><span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"199\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\" | 页大小:\"</span> <span class=\"token operator\"><<</span> pageSize <span class=\"token operator\"><<</span> <span class=\"token string\">\" |\"</span> <span class=\"token operator\"><<</span><span class=\"token string\">\" 专业 |\"</span><span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"200\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\" | 最大逻辑地址:\"</span> <span class=\"token operator\"><<</span> logicalMaxAddress <span class=\"token operator\"><<</span> <span class=\"token string\">\" |\"</span> <span class=\"token operator\"><<</span><span class=\"token string\">\" OS 课程设计 |\"</span><span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"201\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\" | 快表尺寸:\"</span> <span class=\"token operator\"><<</span> fastTableDimensions <span class=\"token operator\"><<</span> <span class=\"token string\">\" |\"</span> <span class=\"token operator\"><<</span><span class=\"token string\">\" 诗岸梦行舟 |\"</span><span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"202\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\" | 页表尺寸:\"</span> <span class=\"token operator\"><<</span> pageTableDimensions <span class=\"token operator\"><<</span> <span class=\"token string\">\" |\"</span> <span class=\"token operator\"><<</span><span class=\"token string\">\" 虚 拟 存 储 器 管 理 |\"</span><span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"203\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\" +------------------------+\"</span> <span class=\"token operator\"><<</span><span class=\"token string\">\"----------------------+\"</span><span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"204\"></td><td><pre> <span class=\"token function\">FastTableVisualization</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"205\"></td><td><pre> <span class=\"token function\">PageTableVisualization</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"206\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"207\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"请输入应用程序请求的逻辑地址:\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"208\"></td><td><pre> cin <span class=\"token operator\">>></span> requestLogicalAddressByOS<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"209\"></td><td><pre> <span class=\"token comment\">// 结束程序</span></pre></td></tr><tr><td data-num=\"210\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>requestLogicalAddressByOS <span class=\"token operator\"><</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"211\"></td><td><pre> <span class=\"token comment\">// 逻辑地址越界</span></pre></td></tr><tr><td data-num=\"212\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>requestLogicalAddressByOS <span class=\"token operator\">></span> logicalMaxAddress<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"213\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Red<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"214\"></td><td><pre></pre></td></tr><tr><td data-num=\"215\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"您请求的地址超出最大逻辑地址!产生越界中断!\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"216\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"217\"></td><td><pre> <span class=\"token function\">sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"218\"></td><td><pre> <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"219\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"220\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Cyan<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"221\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"您请求的十进制地址:\"</span> <span class=\"token operator\"><<</span> requestLogicalAddressByOS <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"222\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"223\"></td><td><pre></pre></td></tr><tr><td data-num=\"224\"></td><td><pre> <span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"225\"></td><td><pre> * 计算逻辑地址数据</pre></td></tr><tr><td data-num=\"226\"></td><td><pre> * P = [A / L]</pre></td></tr><tr><td data-num=\"227\"></td><td><pre> * d = A % L</pre></td></tr><tr><td data-num=\"228\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"229\"></td><td><pre> logicalAddress<span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> requestLogicalAddressByOS <span class=\"token operator\">/</span> pageSize<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"230\"></td><td><pre> logicalAddress<span class=\"token punctuation\">.</span>inPageAddress <span class=\"token operator\">=</span> requestLogicalAddressByOS <span class=\"token operator\">%</span> pageSize<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"231\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"计算后形成逻辑地址:\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"232\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Magenta<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"233\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"+---页号---+---页内地址----+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"234\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"| \"</span> <span class=\"token operator\"><<</span> logicalAddress<span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\"><<</span> <span class=\"token string\">\" | \"</span> <span class=\"token operator\"><<</span> logicalAddress<span class=\"token punctuation\">.</span>inPageAddress <span class=\"token operator\"><<</span> <span class=\"token string\">\" |\"</span></pre></td></tr><tr><td data-num=\"235\"></td><td><pre> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"236\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"+----------+---------------+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"237\"></td><td><pre><span class=\"token comment\">// cout<<\"按回车继续执行...\";</span></pre></td></tr><tr><td data-num=\"238\"></td><td><pre><span class=\"token comment\">// cin.get();cin.get();</span></pre></td></tr><tr><td data-num=\"239\"></td><td><pre></pre></td></tr><tr><td data-num=\"240\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"241\"></td><td><pre> <span class=\"token comment\">// CPU 检索块表</span></pre></td></tr><tr><td data-num=\"242\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"操作系统检索快表...\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"243\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> fastTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"244\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber <span class=\"token operator\">==</span> logicalAddress<span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">&&</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"245\"></td><td><pre> <span class=\"token comment\">// 在快表中发现了与之对应的页号的数据页</span></pre></td></tr><tr><td data-num=\"246\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Green<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"247\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"操作系统在快表中发现了相应的数据页!\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"248\"></td><td><pre> fastTableFindPoint <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"249\"></td><td><pre> <span class=\"token comment\">// 将发现检查位置真</span></pre></td></tr><tr><td data-num=\"250\"></td><td><pre> fastTableFind <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"251\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"252\"></td><td><pre> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"253\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"254\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"255\"></td><td><pre></pre></td></tr><tr><td data-num=\"256\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>fastTableFind<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"257\"></td><td><pre> <span class=\"token comment\">// 快表中没有,访问页表</span></pre></td></tr><tr><td data-num=\"258\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Yellow<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"259\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"快表中没有发现相应的数据页!\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"260\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"261\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"操作系统检索页表...\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"262\"></td><td><pre> <span class=\"token comment\">// 从内存中(页表)寻找所缺失的页</span></pre></td></tr><tr><td data-num=\"263\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> pageTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"264\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber <span class=\"token operator\">==</span> logicalAddress<span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">&&</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"265\"></td><td><pre> <span class=\"token comment\">// 在内存中(页表)找到了数据页</span></pre></td></tr><tr><td data-num=\"266\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Green<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"267\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"操作系统在页表中发现了相应的数据页!\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"268\"></td><td><pre> pageTableFind <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"269\"></td><td><pre> pageTableFindPoint <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"270\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"271\"></td><td><pre> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"272\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"273\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"274\"></td><td><pre></pre></td></tr><tr><td data-num=\"275\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>pageTableFind<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"276\"></td><td><pre> <span class=\"token comment\">// 页表(内存)中没有</span></pre></td></tr><tr><td data-num=\"277\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Yellow<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"278\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"页中没有发现相应的数据页!\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"279\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"280\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"操作系统会正在从外存中抽取页...\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"281\"></td><td><pre> <span class=\"token comment\">// 从外存中抽取页</span></pre></td></tr><tr><td data-num=\"282\"></td><td><pre> externalMemoryDataStruct externalMemoryFindPage <span class=\"token operator\">=</span> <span class=\"token function\">LookMissingPageFromExternalMemory</span><span class=\"token punctuation\">(</span></pre></td></tr><tr><td data-num=\"283\"></td><td><pre> logicalAddress<span class=\"token punctuation\">.</span>pageNumber<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"284\"></td><td><pre> <span class=\"token comment\">/*cout<<externalMemoryFindPage.externalPageNumber<<\" \"<<externalMemoryFindPage.externalBlockNumber;*/</span></pre></td></tr><tr><td data-num=\"285\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"成功抽取到了,现在正在检查内存是否已满...\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"286\"></td><td><pre> <span class=\"token function\">sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"287\"></td><td><pre></pre></td></tr><tr><td data-num=\"288\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>remainingCapacityOfPageTable <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"289\"></td><td><pre> <span class=\"token comment\">// 内存(页表)已满</span></pre></td></tr><tr><td data-num=\"290\"></td><td><pre> <span class=\"token comment\">// 这里得选择一个最没用的一页对换出去</span></pre></td></tr><tr><td data-num=\"291\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Red<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"292\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"内存已满,操作系统需要进行页面置换,正在选择一个最没用的一页进行换出...\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"293\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"294\"></td><td><pre> <span class=\"token comment\">// 开始选择一个最没用的一页</span></pre></td></tr><tr><td data-num=\"295\"></td><td><pre> <span class=\"token comment\">// 页表置换排行榜</span></pre></td></tr><tr><td data-num=\"296\"></td><td><pre> rankForPageTableDataStruct rankForPageTable<span class=\"token punctuation\">[</span>pageTableDimensions<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"297\"></td><td><pre> <span class=\"token comment\">// 初始化排行榜</span></pre></td></tr><tr><td data-num=\"298\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> pageTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"299\"></td><td><pre> rankForPageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"300\"></td><td><pre> rankForPageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"301\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"302\"></td><td><pre> <span class=\"token comment\">// 模拟态桶排序</span></pre></td></tr><tr><td data-num=\"303\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> pageTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"304\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"305\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"306\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"307\"></td><td><pre> rankForPageTable<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"308\"></td><td><pre> rankForPageTable<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"309\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"310\"></td><td><pre> <span class=\"token operator\">&&</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"311\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"312\"></td><td><pre> rankForPageTable<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"313\"></td><td><pre> rankForPageTable<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"314\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"315\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"316\"></td><td><pre> <span class=\"token operator\">&&</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"317\"></td><td><pre> rankForPageTable<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"318\"></td><td><pre> rankForPageTable<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"319\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"320\"></td><td><pre> rankForPageTable<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"321\"></td><td><pre> rankForPageTable<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"322\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"323\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"324\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> pageTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"325\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>rankForPageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">!=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"326\"></td><td><pre> <span class=\"token comment\">// 找到一个没用的页</span></pre></td></tr><tr><td data-num=\"327\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Green<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"328\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"操作系统页表表选择了一个页号为\"</span></pre></td></tr><tr><td data-num=\"329\"></td><td><pre> <span class=\"token operator\"><<</span> pageTable<span class=\"token punctuation\">[</span>rankForPageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber</pre></td></tr><tr><td data-num=\"330\"></td><td><pre> <span class=\"token operator\"><<</span> <span class=\"token string\">\"的页进行换出...\"</span></pre></td></tr><tr><td data-num=\"331\"></td><td><pre> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"332\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"333\"></td><td><pre> <span class=\"token function\">sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"334\"></td><td><pre> <span class=\"token comment\">// 把页表中对应的页号置为无效</span></pre></td></tr><tr><td data-num=\"335\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>rankForPageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"336\"></td><td><pre> <span class=\"token comment\">// 页表页面置换</span></pre></td></tr><tr><td data-num=\"337\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>rankForPageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber <span class=\"token operator\">=</span> externalMemoryFindPage<span class=\"token punctuation\">.</span>externalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"338\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>rankForPageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalBlockNumber <span class=\"token operator\">=</span> externalMemoryFindPage<span class=\"token punctuation\">.</span>externalBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"339\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>rankForPageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"340\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>rankForPageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"341\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>rankForPageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"342\"></td><td><pre></pre></td></tr><tr><td data-num=\"343\"></td><td><pre> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"344\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"345\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"346\"></td><td><pre></pre></td></tr><tr><td data-num=\"347\"></td><td><pre></pre></td></tr><tr><td data-num=\"348\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"349\"></td><td><pre> <span class=\"token comment\">// 内存(页表)仍有空间</span></pre></td></tr><tr><td data-num=\"350\"></td><td><pre> <span class=\"token comment\">// 有空间就可以塞进去</span></pre></td></tr><tr><td data-num=\"351\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Blue<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"352\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"内存还有空间,操作系统正在读取缺页并回写内存中...\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"353\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"354\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> pageTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"355\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"356\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"357\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber <span class=\"token operator\">=</span> externalMemoryFindPage<span class=\"token punctuation\">.</span>externalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"358\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalBlockNumber <span class=\"token operator\">=</span> externalMemoryFindPage<span class=\"token punctuation\">.</span>externalBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"359\"></td><td><pre> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"360\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"361\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"362\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Green<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"363\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"页表回写成功!\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"364\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"365\"></td><td><pre> <span class=\"token comment\">// 塞完就减减</span></pre></td></tr><tr><td data-num=\"366\"></td><td><pre> remainingCapacityOfPageTable<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"367\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"368\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>remainingCapacityOfFastTable <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"369\"></td><td><pre> <span class=\"token comment\">// 快表没有空间了</span></pre></td></tr><tr><td data-num=\"370\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Red<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"371\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"快表已满,操作系统需要进行页面置换,正在选择一个最没用的一页进行换出...\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"372\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"373\"></td><td><pre> <span class=\"token comment\">// 选择一个最没用的一页进行换出!!!!!!!!!!</span></pre></td></tr><tr><td data-num=\"374\"></td><td><pre> <span class=\"token keyword\">bool</span> fastTableFindCheckIsTrue <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"375\"></td><td><pre> <span class=\"token keyword\">int</span> fastTableFindCheckIndex<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"376\"></td><td><pre> <span class=\"token comment\">// 快表置换排行榜</span></pre></td></tr><tr><td data-num=\"377\"></td><td><pre> rankForFastTableDataStruct rankForFastTable<span class=\"token punctuation\">[</span>fastTableDimensions<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"378\"></td><td><pre> <span class=\"token comment\">// 初始化排行榜</span></pre></td></tr><tr><td data-num=\"379\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> fastTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"380\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"381\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"382\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"383\"></td><td><pre> <span class=\"token comment\">// 模拟态桶排序</span></pre></td></tr><tr><td data-num=\"384\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> fastTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"385\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"386\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"387\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"388\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"389\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"390\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"391\"></td><td><pre> <span class=\"token operator\">&&</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"392\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"393\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"394\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"395\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"396\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"397\"></td><td><pre> <span class=\"token operator\">&&</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"398\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"399\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"400\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"401\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"402\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"403\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"404\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"405\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> fastTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"406\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">!=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"407\"></td><td><pre> <span class=\"token comment\">// 找到一个没用的页</span></pre></td></tr><tr><td data-num=\"408\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Green<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"409\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"操作系统在快表选择了一个页号为\"</span></pre></td></tr><tr><td data-num=\"410\"></td><td><pre> <span class=\"token operator\"><<</span> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber</pre></td></tr><tr><td data-num=\"411\"></td><td><pre> <span class=\"token operator\"><<</span> <span class=\"token string\">\"的页进行换出...\"</span></pre></td></tr><tr><td data-num=\"412\"></td><td><pre> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"413\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"414\"></td><td><pre> <span class=\"token function\">sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"415\"></td><td><pre> <span class=\"token comment\">// 把快表中对应的页号置为无效</span></pre></td></tr><tr><td data-num=\"416\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"417\"></td><td><pre> <span class=\"token comment\">// 快表页面置换</span></pre></td></tr><tr><td data-num=\"418\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber <span class=\"token operator\">=</span> externalMemoryFindPage<span class=\"token punctuation\">.</span>externalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"419\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableBlockNumber <span class=\"token operator\">=</span> externalMemoryFindPage<span class=\"token punctuation\">.</span>externalBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"420\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"421\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"422\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"423\"></td><td><pre></pre></td></tr><tr><td data-num=\"424\"></td><td><pre> <span class=\"token comment\">// 把页表中对应的页号置为无效?</span></pre></td></tr><tr><td data-num=\"425\"></td><td><pre> fastTableFindCheckIsTrue <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"426\"></td><td><pre> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"427\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"428\"></td><td><pre></pre></td></tr><tr><td data-num=\"429\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"430\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTableFindCheckIsTrue<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"431\"></td><td><pre></pre></td></tr><tr><td data-num=\"432\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"433\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Red<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"434\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"一般不存在这种情况,以防万一留着DeBug用\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"435\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"436\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"437\"></td><td><pre></pre></td></tr><tr><td data-num=\"438\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"439\"></td><td><pre> <span class=\"token comment\">// 快表仍然有空间</span></pre></td></tr><tr><td data-num=\"440\"></td><td><pre> <span class=\"token comment\">// 有空间就塞</span></pre></td></tr><tr><td data-num=\"441\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Blue<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"442\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"快表还有空间,操作系统正在读取缺页并回写内存中...\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"443\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"444\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> fastTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"445\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"446\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"447\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber <span class=\"token operator\">=</span> externalMemoryFindPage<span class=\"token punctuation\">.</span>externalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"448\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableBlockNumber <span class=\"token operator\">=</span> externalMemoryFindPage<span class=\"token punctuation\">.</span>externalBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"449\"></td><td><pre> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"450\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"451\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"452\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Green<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"453\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"快表回写成功!\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"454\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"455\"></td><td><pre> <span class=\"token comment\">// 塞完就减减</span></pre></td></tr><tr><td data-num=\"456\"></td><td><pre> remainingCapacityOfFastTable<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"457\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"458\"></td><td><pre> <span class=\"token comment\">//!!!!!!!!!!!!!!</span></pre></td></tr><tr><td data-num=\"459\"></td><td><pre></pre></td></tr><tr><td data-num=\"460\"></td><td><pre> physicalAddress<span class=\"token punctuation\">.</span>blockNumber <span class=\"token operator\">=</span> externalMemoryFindPage<span class=\"token punctuation\">.</span>externalBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"461\"></td><td><pre> physicalAddress<span class=\"token punctuation\">.</span>internalBlockAddress <span class=\"token operator\">=</span> logicalAddress<span class=\"token punctuation\">.</span>inPageAddress<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"462\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"计算后得到物理地址:\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"463\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Magenta<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"464\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"+---块号---+---块内地址----+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"465\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"| \"</span> <span class=\"token operator\"><<</span> physicalAddress<span class=\"token punctuation\">.</span>blockNumber <span class=\"token operator\"><<</span> <span class=\"token string\">\" | \"</span> <span class=\"token operator\"><<</span> physicalAddress<span class=\"token punctuation\">.</span>internalBlockAddress</pre></td></tr><tr><td data-num=\"466\"></td><td><pre> <span class=\"token operator\"><<</span> <span class=\"token string\">\" |\"</span></pre></td></tr><tr><td data-num=\"467\"></td><td><pre> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"468\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"+----------+---------------+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"469\"></td><td><pre> <span class=\"token function\">sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"470\"></td><td><pre></pre></td></tr><tr><td data-num=\"471\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"472\"></td><td><pre> <span class=\"token comment\">// 页表中有</span></pre></td></tr><tr><td data-num=\"473\"></td><td><pre> <span class=\"token comment\">// 页表中的话,修改页表后还需要进行快表置换</span></pre></td></tr><tr><td data-num=\"474\"></td><td><pre> <span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"475\"></td><td><pre> * 如果页表里面有,那就更改他的访问位和修改位,</pre></td></tr><tr><td data-num=\"476\"></td><td><pre> * 为了编写简单,在这里我做出一个规定:</pre></td></tr><tr><td data-num=\"477\"></td><td><pre> * 当应用程序第一次访问时将访问位置真,</pre></td></tr><tr><td data-num=\"478\"></td><td><pre> * 当应用程序第二次访问时将修改为置真。</pre></td></tr><tr><td data-num=\"479\"></td><td><pre> * 这么做也是相对合理的,原因如下:</pre></td></tr><tr><td data-num=\"480\"></td><td><pre> * 访问位与修改位联合置换逻辑(修改,访问)即对换优先级:</pre></td></tr><tr><td data-num=\"481\"></td><td><pre> * * * 1.(0,0)</pre></td></tr><tr><td data-num=\"482\"></td><td><pre> * * * 2.(0,1)</pre></td></tr><tr><td data-num=\"483\"></td><td><pre> * * * 3.(1,0)</pre></td></tr><tr><td data-num=\"484\"></td><td><pre> * * * 4.(1,1)</pre></td></tr><tr><td data-num=\"485\"></td><td><pre> * 排名越高,置换优先级越高,</pre></td></tr><tr><td data-num=\"486\"></td><td><pre> * 相对来讲,访问位与修改位置真后,访问位优先级高于修改位</pre></td></tr><tr><td data-num=\"487\"></td><td><pre> * 其实我懒了 但我不说(qwq)</pre></td></tr><tr><td data-num=\"488\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"489\"></td><td><pre> <span class=\"token comment\">// 快表置换,基于页表</span></pre></td></tr><tr><td data-num=\"490\"></td><td><pre> <span class=\"token comment\">// 快表置换排行榜</span></pre></td></tr><tr><td data-num=\"491\"></td><td><pre> rankForFastTableDataStruct rankForFastTable<span class=\"token punctuation\">[</span>fastTableDimensions<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"492\"></td><td><pre> <span class=\"token comment\">// 初始化排行榜</span></pre></td></tr><tr><td data-num=\"493\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> fastTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"494\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"495\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"496\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"497\"></td><td><pre> <span class=\"token comment\">// 模拟态桶排序</span></pre></td></tr><tr><td data-num=\"498\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> fastTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"499\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"500\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"501\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"502\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"503\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"504\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"505\"></td><td><pre> <span class=\"token operator\">&&</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"506\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"507\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"508\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"509\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"510\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"511\"></td><td><pre> <span class=\"token operator\">&&</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"512\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"513\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"514\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"515\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"516\"></td><td><pre> rankForFastTable<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">=</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"517\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"518\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"519\"></td><td><pre></pre></td></tr><tr><td data-num=\"520\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> fastTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"521\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pageNumber <span class=\"token operator\">!=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"522\"></td><td><pre> <span class=\"token comment\">// 找到一个没用的页</span></pre></td></tr><tr><td data-num=\"523\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Green<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"524\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"操作系统在快表选择了一个页号为\"</span></pre></td></tr><tr><td data-num=\"525\"></td><td><pre> <span class=\"token operator\"><<</span> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber</pre></td></tr><tr><td data-num=\"526\"></td><td><pre> <span class=\"token operator\"><<</span> <span class=\"token string\">\"的页进行换出...\"</span></pre></td></tr><tr><td data-num=\"527\"></td><td><pre> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"528\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"529\"></td><td><pre> <span class=\"token function\">sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"530\"></td><td><pre> <span class=\"token comment\">// 把快表中对应的页号置为无效</span></pre></td></tr><tr><td data-num=\"531\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"532\"></td><td><pre> <span class=\"token comment\">// 快表页面置换</span></pre></td></tr><tr><td data-num=\"533\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber <span class=\"token operator\">=</span> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"534\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableBlockNumber <span class=\"token operator\">=</span> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"535\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"536\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"537\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>rankForFastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"538\"></td><td><pre> <span class=\"token comment\">// 物理地址存储</span></pre></td></tr><tr><td data-num=\"539\"></td><td><pre> physicalAddress<span class=\"token punctuation\">.</span>blockNumber <span class=\"token operator\">=</span> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"540\"></td><td><pre> physicalAddress<span class=\"token punctuation\">.</span>internalBlockAddress <span class=\"token operator\">=</span> logicalAddress<span class=\"token punctuation\">.</span>inPageAddress<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"541\"></td><td><pre> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"542\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"543\"></td><td><pre></pre></td></tr><tr><td data-num=\"544\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"545\"></td><td><pre></pre></td></tr><tr><td data-num=\"546\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"计算后得到物理地址:\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"547\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Magenta<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"548\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"+---块号---+---块内地址----+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"549\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"| \"</span> <span class=\"token operator\"><<</span> physicalAddress<span class=\"token punctuation\">.</span>blockNumber <span class=\"token operator\"><<</span> <span class=\"token string\">\" | \"</span> <span class=\"token operator\"><<</span> physicalAddress<span class=\"token punctuation\">.</span>internalBlockAddress</pre></td></tr><tr><td data-num=\"550\"></td><td><pre> <span class=\"token operator\"><<</span> <span class=\"token string\">\" |\"</span></pre></td></tr><tr><td data-num=\"551\"></td><td><pre> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"552\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"+----------+---------------+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"553\"></td><td><pre></pre></td></tr><tr><td data-num=\"554\"></td><td><pre></pre></td></tr><tr><td data-num=\"555\"></td><td><pre> <span class=\"token comment\">// 修改页表</span></pre></td></tr><tr><td data-num=\"556\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"557\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"558\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"559\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"560\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"561\"></td><td><pre> <span class=\"token operator\">&&</span> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"562\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"563\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"564\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"565\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"566\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"567\"></td><td><pre> <span class=\"token operator\">&&</span> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"568\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"569\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"570\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"571\"></td><td><pre> <span class=\"token comment\">// 同步快表</span></pre></td></tr><tr><td data-num=\"572\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> fastTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"573\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber <span class=\"token operator\">==</span> pageTable<span class=\"token punctuation\">[</span>pageTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"574\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"575\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"576\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"577\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"578\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"579\"></td><td><pre> <span class=\"token operator\">&&</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"580\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"581\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"582\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"583\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"584\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"585\"></td><td><pre> <span class=\"token operator\">&&</span> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"586\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"587\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"588\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"589\"></td><td><pre> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"590\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"591\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"592\"></td><td><pre></pre></td></tr><tr><td data-num=\"593\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"594\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"595\"></td><td><pre> <span class=\"token comment\">// 快表中有</span></pre></td></tr><tr><td data-num=\"596\"></td><td><pre> <span class=\"token comment\">// 修改快表</span></pre></td></tr><tr><td data-num=\"597\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"598\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"599\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"600\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"601\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"602\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"603\"></td><td><pre> <span class=\"token operator\">&&</span> fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"604\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"605\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"606\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"607\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"608\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"609\"></td><td><pre> <span class=\"token operator\">&&</span> fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"610\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"611\"></td><td><pre> fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"612\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"613\"></td><td><pre> <span class=\"token comment\">// 同步页表</span></pre></td></tr><tr><td data-num=\"614\"></td><td><pre> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\"><</span> pageTableDimensions<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"615\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>internalPageNumber <span class=\"token operator\">==</span> fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTablePageNumber<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"616\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"617\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"618\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"619\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"620\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"621\"></td><td><pre> <span class=\"token operator\">&&</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"622\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"623\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"624\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"625\"></td><td><pre> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>validBit</pre></td></tr><tr><td data-num=\"626\"></td><td><pre> <span class=\"token operator\">&&</span> <span class=\"token operator\">!</span>pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit</pre></td></tr><tr><td data-num=\"627\"></td><td><pre> <span class=\"token operator\">&&</span> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"628\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>accessBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"629\"></td><td><pre> pageTable<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>modifyBit <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"630\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"631\"></td><td><pre> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"632\"></td><td><pre></pre></td></tr><tr><td data-num=\"633\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"634\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"635\"></td><td><pre></pre></td></tr><tr><td data-num=\"636\"></td><td><pre> <span class=\"token comment\">// 直接从快表中提取</span></pre></td></tr><tr><td data-num=\"637\"></td><td><pre> physicalAddress<span class=\"token punctuation\">.</span>blockNumber <span class=\"token operator\">=</span> fastTable<span class=\"token punctuation\">[</span>fastTableFindPoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fastTableBlockNumber<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"638\"></td><td><pre> physicalAddress<span class=\"token punctuation\">.</span>internalBlockAddress <span class=\"token operator\">=</span> logicalAddress<span class=\"token punctuation\">.</span>inPageAddress<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"639\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"计算后得到物理地址:\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"640\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Magenta<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"641\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"+---块号---+---块内地址----+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"642\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"| \"</span> <span class=\"token operator\"><<</span> physicalAddress<span class=\"token punctuation\">.</span>blockNumber <span class=\"token operator\"><<</span> <span class=\"token string\">\" | \"</span> <span class=\"token operator\"><<</span> physicalAddress<span class=\"token punctuation\">.</span>internalBlockAddress</pre></td></tr><tr><td data-num=\"643\"></td><td><pre> <span class=\"token operator\"><<</span> <span class=\"token string\">\" |\"</span></pre></td></tr><tr><td data-num=\"644\"></td><td><pre> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"645\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"+----------+---------------+\"</span> <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"646\"></td><td><pre> <span class=\"token function\">sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"647\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"648\"></td><td><pre> <span class=\"token comment\">// 恢复初始状态</span></pre></td></tr><tr><td data-num=\"649\"></td><td><pre> fastTableFind <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"650\"></td><td><pre> pageTableFind <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"651\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>Green<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"652\"></td><td><pre> <span class=\"token function\">sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"653\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"---------------地址变换结束---------------\"</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"654\"></td><td><pre> <span class=\"token function\">sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"655\"></td><td><pre> cout <span class=\"token operator\"><<</span> endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"656\"></td><td><pre> <span class=\"token function\">setConsoleColor</span><span class=\"token punctuation\">(</span>White<span class=\"token punctuation\">,</span> Black<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"657\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"658\"></td><td><pre> cout <span class=\"token operator\"><<</span> <span class=\"token string\">\"下次再见!\"</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"659\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure>",
"tags": [
"操作系统",
"OS"
]
},
{
"id": "https://735690757.github.io/MongoDB/MongoDB03/",
"url": "https://735690757.github.io/MongoDB/MongoDB03/",
"title": "MongoDB初步使用",
"date_published": "2023-09-13T04:20:00.000Z",
"content_html": "<h1 id=\"mongodb约束命令\"><a class=\"markdownIt-Anchor\" href=\"#mongodb约束命令\">#</a> MongoDB 约束命令</h1>\n<h2 id=\"输出行数限制\"><a class=\"markdownIt-Anchor\" href=\"#输出行数限制\">#</a> 输出行数限制</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t4.aggregate<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token variable\">$limit</span>:4<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><h2 id=\"xx升序降序\"><a class=\"markdownIt-Anchor\" href=\"#xx升序降序\">#</a> xx 升序 / 降序</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t4.aggregate<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span><span class=\"token variable\">$sort</span>:<span class=\"token punctuation\">{</span>price:-1<span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><p>1:升序</p>\n<p>2:降序</p>\n<h2 id=\"mapreduce\"><a class=\"markdownIt-Anchor\" href=\"#mapreduce\">#</a> MapReduce</h2>\n<p>MapReduce 是一种用于分布式计算的编程模型和处理大规模数据集的方法。</p>\n<p>MapReduce 模型的基本思想是将大规模数据集分成小块,然后并行处理这些小块数据以生成中间结果。</p>\n<ol>\n<li><strong>Map 阶段(映射阶段)</strong>:在这个阶段,原始数据被映射成键 - 值对的形式。每个映射操作都是独立的,可以在不同的计算节点上并行执行。Map 操作通常用于筛选、过滤、排序和转换数据。</li>\n<li><strong>Reduce 阶段(归约阶段)</strong>:在 Map 阶段之后,所有的中间结果按键分组,并将每个组的数据传递给 Reduce 函数进行聚合和处理。Reduce 操作通常用于对数据进行汇总、计数、计算统计信息等操作。</li>\n</ol>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>//MapReduce</pre></td></tr><tr><td data-num=\"2\"></td><td><pre>//map映射</pre></td></tr><tr><td data-num=\"3\"></td><td><pre>var map <span class=\"token operator\">=</span> <span class=\"token function-name function\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> emit<span class=\"token punctuation\">(</span>this.type,this.name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre>//reduce减少并以“,”分割</pre></td></tr><tr><td data-num=\"7\"></td><td><pre>var reduce <span class=\"token operator\">=</span> function<span class=\"token punctuation\">(</span>key,values<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token builtin class-name\">return</span> values.join<span class=\"token punctuation\">(</span><span class=\"token string\">','</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre>//选项设置输出</pre></td></tr><tr><td data-num=\"11\"></td><td><pre>var <span class=\"token assign-left variable\">opt</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>out:<span class=\"token string\">\"name_list\"</span><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre>db.t4.mapReduce<span class=\"token punctuation\">(</span>map,reduce,opt<span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote>\n<p>[<br>\n{<br>\n“_id”: “电子设备”,<br>\n“value”: “logi”<br>\n},<br>\n{<br>\n“_id”: “服装”,<br>\n“value”: “安踏,lining”<br>\n},<br>\n{<br>\n“_id”: “电子通信”,<br>\n“value”: “oppo,vivo,huawei,iphone8”<br>\n},<br>\n{<br>\n“_id”: “饮品”,<br>\n“value”: “康师傅”<br>\n}<br>\n]</p>\n</blockquote>\n",
"tags": [
"MongoDB",
"MongoDB"
]
},
{
"id": "https://735690757.github.io/MongoDB/MongoDB02/",
"url": "https://735690757.github.io/MongoDB/MongoDB02/",
"title": "MongoDB初步使用",
"date_published": "2023-09-06T04:20:00.000Z",
"content_html": "<h1 id=\"mongodb命令\"><a class=\"markdownIt-Anchor\" href=\"#mongodb命令\">#</a> MongoDB 命令</h1>\n<h2 id=\"创建用户可读可写\"><a class=\"markdownIt-Anchor\" href=\"#创建用户可读可写\">#</a> 创建用户(可读可写)</h2>\n<h3 id=\"创建\"><a class=\"markdownIt-Anchor\" href=\"#创建\">#</a> 创建</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.createUser<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>user:<span class=\"token string\">\"lkr40\"</span>,pwd:<span class=\"token string\">\"123456\"</span>,roles:<span class=\"token punctuation\">[</span><span class=\"token string\">\"readWrite\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><h3 id=\"检验\"><a class=\"markdownIt-Anchor\" href=\"#检验\">#</a> 检验</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.auth<span class=\"token punctuation\">(</span><span class=\"token string\">\"lkr40\"</span>,<span class=\"token string\">\"123456\"</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote>\n<p>db.createUser({user:“lkr40”,pwd:“123456”,roles:[“readWrite”]})<br>\nSuccessfully added user: { “user” : “lkr40”, “roles” : [ “readWrite” ] }<br>\ndb.auth(“lkr40”,“123456”)<br>\n1</p>\n</blockquote>\n<h3 id=\"登录\"><a class=\"markdownIt-Anchor\" href=\"#登录\">#</a> 登录</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>mongo <span class=\"token number\">127.0</span>.0.1:27017/mymongo <span class=\"token parameter variable\">-u</span> lkr40 <span class=\"token parameter variable\">-p</span> <span class=\"token number\">123456</span></pre></td></tr></table></figure><h2 id=\"建立使用数据库\"><a class=\"markdownIt-Anchor\" href=\"#建立使用数据库\">#</a> 建立 / 使用数据库</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>use mymongo</pre></td></tr></table></figure><blockquote>\n<p>use mymongo<br>\nswitched to db mymongo</p>\n</blockquote>\n<h2 id=\"查询当前数据库\"><a class=\"markdownIt-Anchor\" href=\"#查询当前数据库\">#</a> 查询当前数据库</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db</pre></td></tr></table></figure><blockquote>\n<p>db<br>\nmymongo</p>\n</blockquote>\n<h2 id=\"删除数据库\"><a class=\"markdownIt-Anchor\" href=\"#删除数据库\">#</a> 删除数据库</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.dropDatabase<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><h2 id=\"查询时间\"><a class=\"markdownIt-Anchor\" href=\"#查询时间\">#</a> 查询时间</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>Date<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote>\n<p>Date()<br>\nWed Sep 06 2023 10:21:36 GMT+0800</p>\n</blockquote>\n<h2 id=\"创建集合\"><a class=\"markdownIt-Anchor\" href=\"#创建集合\">#</a> 创建集合</h2>\n<p><strong>集合中可以包含子集合</strong></p>\n<h3 id=\"显式创建t\"><a class=\"markdownIt-Anchor\" href=\"#显式创建t\">#</a> 显式创建(t)</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.createCollection<span class=\"token punctuation\">(</span><span class=\"token string\">\"t\"</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote ok:1=\"\">\n<p>db.createCollection(“t”)</p>\n</blockquote>\n<h3 id=\"隐式创建t1\"><a class=\"markdownIt-Anchor\" href=\"#隐式创建t1\">#</a> 隐式创建(t1)</h3>\n<pre><code>db.t1.insert({"age":18})\n</code></pre>\n<blockquote>\n<p>db.t1.insert({“age”:18})<br>\nWriteResult({ “nInserted” : 1 })<br>\nshow collections<br>\nt<br>\nt1</p>\n</blockquote>\n<h2 id=\"展示集合\"><a class=\"markdownIt-Anchor\" href=\"#展示集合\">#</a> 展示集合</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>show collections</pre></td></tr></table></figure><blockquote>\n<p>show collections<br>\nt</p>\n<p>t1</p>\n</blockquote>\n<h2 id=\"删除集合\"><a class=\"markdownIt-Anchor\" href=\"#删除集合\">#</a> 删除集合</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t.drop<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote>\n<p>db.t.drop()<br>\ntrue</p>\n</blockquote>\n<h2 id=\"查询文档\"><a class=\"markdownIt-Anchor\" href=\"#查询文档\">#</a> 查询文档</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t1.find<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote _id:ObjectId(64f7ec7bff2142d2a2445360),age:18=\"\">\n<p>db.t1.find()</p>\n</blockquote>\n<h3 id=\"条件查询\"><a class=\"markdownIt-Anchor\" href=\"#条件查询\">#</a> 条件查询</h3>\n<h4 id=\"等于\"><a class=\"markdownIt-Anchor\" href=\"#等于\">#</a> 等于</h4>\n<pre><code>db.t.find({"x":1})\n</code></pre>\n<blockquote _id:ObjectId(64f7f05bff2142d2a2445361),x:1=\"\">\n<p>db.t.find({“x”:1})</p>\n</blockquote>\n<h4 id=\"小于\"><a class=\"markdownIt-Anchor\" href=\"#小于\">#</a> 小于</h4>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t.find<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"x\"</span>:<span class=\"token punctuation\">{</span><span class=\"token variable\">$lte</span> <span class=\"token builtin class-name\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><h4 id=\"大于\"><a class=\"markdownIt-Anchor\" href=\"#大于\">#</a> 大于</h4>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t.find<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"x\"</span>:<span class=\"token punctuation\">{</span><span class=\"token variable\">$lte</span> <span class=\"token builtin class-name\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><h4 id=\"在之中包含\"><a class=\"markdownIt-Anchor\" href=\"#在之中包含\">#</a> 在之中(包含)</h4>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t.find<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"x\"</span>:<span class=\"token punctuation\">{</span><span class=\"token variable\">$in</span> <span class=\"token builtin class-name\">:</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1,3</span>,5<span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><h4 id=\"不在其中不包含\"><a class=\"markdownIt-Anchor\" href=\"#不在其中不包含\">#</a> 不在其中(不包含)</h4>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t.find<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"x\"</span>:<span class=\"token punctuation\">{</span><span class=\"token variable\">$nin</span> <span class=\"token builtin class-name\">:</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1,3</span>,5<span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><h2 id=\"插入文档\"><a class=\"markdownIt-Anchor\" href=\"#插入文档\">#</a> 插入文档</h2>\n<h3 id=\"单一插入\"><a class=\"markdownIt-Anchor\" href=\"#单一插入\">#</a> 单一插入</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t1.insert<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"_id\"</span><span class=\"token builtin class-name\">:</span><span class=\"token string\">\"1\"</span>,<span class=\"token string\">\"age\"</span>:23<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote _id:1,age:23=\"\" _id:ObjectId(64f7ec7bff2142d2a2445360),age:18=\"\">\n<p>db.t1.insert({"_id":“1”,“age”:23})<br>\nWriteResult({ “nInserted” : 1 })<br>\ndb.t1.find()<br>\n</p>\n</blockquote>\n<h3 id=\"批量插入单语句\"><a class=\"markdownIt-Anchor\" href=\"#批量插入单语句\">#</a> 批量插入(单语句)</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t1.insertMany<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"_id\"</span>:2,<span class=\"token string\">\"age\"</span>:65<span class=\"token punctuation\">}</span>,<span class=\"token punctuation\">{</span><span class=\"token string\">\"_id\"</span>:3,<span class=\"token string\">\"age\"</span>:45<span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote _id:3,age:45=\"\" _id:2,age:65=\"\">\n<p>db.t1.insertMany([{"_id":2,“age”:65},{"_id":3,“age”:45}])<br>\n{ “acknowledged” : true, “insertedIds” : [ 2, 3 ] }<br>\ndb.t1.find()<br>\n{ “_id” : ObjectId(“64f7ec7bff2142d2a2445360”), “age” : 18 }<br>\n{ “_id” : “1”, “age” : 33 }<br>\n</p>\n</blockquote>\n<h3 id=\"循环插入for\"><a class=\"markdownIt-Anchor\" href=\"#循环插入for\">#</a> 循环插入(for)</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>for<span class=\"token punctuation\">(</span>i<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>i<span class=\"token operator\"><</span><span class=\"token number\">9</span><span class=\"token punctuation\">;</span>i++<span class=\"token punctuation\">)</span> db.t.insert<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"x\"</span>:i<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote _id:ObjectId(64f7f05cff2142d2a2445368),x:8=\"\" _id:ObjectId(64f7f05cff2142d2a2445367),x:7=\"\">\n<p>for(i=1;i<9;i++) db.t.insert({“x”:i})<br>\nWriteResult({ “nInserted” : 1 })<br>\ndb.t.find()<br>\n{ “_id” : ObjectId(“64f7f05bff2142d2a2445361”), “x” : 1 }<br>\n{ “_id” : ObjectId(“64f7f05cff2142d2a2445362”), “x” : 2 }<br>\n{ “_id” : ObjectId(“64f7f05cff2142d2a2445363”), “x” : 3 }<br>\n{ “_id” : ObjectId(“64f7f05cff2142d2a2445364”), “x” : 4 }<br>\n{ “_id” : ObjectId(“64f7f05cff2142d2a2445365”), “x” : 5 }<br>\n{ “_id” : ObjectId(“64f7f05cff2142d2a2445366”), “x” : 6 }<br>\n</p>\n</blockquote>\n<h3 id=\"同id插入异常\"><a class=\"markdownIt-Anchor\" href=\"#同id插入异常\">#</a> 同 id 插入异常</h3>\n<blockquote>\n<p>db.t1.insert({"_id":“1”,“age”:23})<br>\nWriteResult({<br>\n“nInserted” : 0,<br>\n“writeError” : {<br>\n“code” : 11000,<br>\n“errmsg” : “E11000 duplicate key error collection: mymongo.t1 index: <em>id</em> dup key: { _id: “1” }”<br>\n}<br>\n})</p>\n</blockquote>\n<h2 id=\"修改输入全部属性替换\"><a class=\"markdownIt-Anchor\" href=\"#修改输入全部属性替换\">#</a> 修改(输入全部属性 / 替换)</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t1.save<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"_id\"</span><span class=\"token builtin class-name\">:</span><span class=\"token string\">\"1\"</span>,<span class=\"token string\">\"age\"</span>:33<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote _id:1,age:33=\"\" _id:ObjectId(64f7ec7bff2142d2a2445360),age:18=\"\">\n<p>db.t1.save({"_id":“1”,“age”:33})<br>\nWriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })<br>\ndb.t1.find()<br>\n</p>\n</blockquote>\n<h2 id=\"更新\"><a class=\"markdownIt-Anchor\" href=\"#更新\">#</a> 更新</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t1.update<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"age\"</span>:65<span class=\"token punctuation\">}</span>,<span class=\"token punctuation\">{</span><span class=\"token variable\">$set</span>:<span class=\"token punctuation\">{</span><span class=\"token string\">\"age\"</span>:100<span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote _id:3,age:45=\"\" _id:2,age:100=\"\">\n<p>db.t1.update({“age”:65},{$set:{“age”:100}})<br>\nWriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })<br>\ndb.t1.find()<br>\n{ “_id” : ObjectId(“64f7ec7bff2142d2a2445360”), “age” : 18 }<br>\n{ “_id” : “1”, “age” : 33 }<br>\n</p>\n</blockquote>\n<h2 id=\"删除\"><a class=\"markdownIt-Anchor\" href=\"#删除\">#</a> 删除</h2>\n<h3 id=\"批量删除\"><a class=\"markdownIt-Anchor\" href=\"#批量删除\">#</a> 批量删除</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t1.remove<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"age\"</span>:33<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote _id:3,age:45=\"\" _id:2,age:100=\"\">\n<p>db.t1.remove({“age”:33})<br>\nWriteResult({ “nRemoved” : 1 })<br>\ndb.t1.find()<br>\n{ “_id” : ObjectId(“64f7ec7bff2142d2a2445360”), “age” : 18 }<br>\n</p>\n</blockquote>\n<h3 id=\"单一删除\"><a class=\"markdownIt-Anchor\" href=\"#单一删除\">#</a> 单一删除</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t1.remove<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"age\"</span>:45<span class=\"token punctuation\">}</span>,<span class=\"token punctuation\">{</span>justOne:1<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote _id:5,age:45=\"\" _id:4,age:65=\"\">\n<p>db.t1.remove({“age”:45},{justOne:1})<br>\nWriteResult({ “nRemoved” : 1 })<br>\ndb.t1.find()<br>\n{ “_id” : ObjectId(“64f7ec7bff2142d2a2445360”), “age” : 18 }<br>\n{ “_id” : 2, “age” : 100 }<br>\n</p>\n</blockquote>\n<h2 id=\"capped限制\"><a class=\"markdownIt-Anchor\" href=\"#capped限制\">#</a> Capped 限制</h2>\n<h3 id=\"创建限制\"><a class=\"markdownIt-Anchor\" href=\"#创建限制\">#</a> 创建限制</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.createCollection<span class=\"token punctuation\">(</span><span class=\"token string\">\"t2\"</span>,<span class=\"token punctuation\">{</span>capped:true,size:3,max:8<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t2.isCapped<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><h3 id=\"检验-2\"><a class=\"markdownIt-Anchor\" href=\"#检验-2\">#</a> 检验</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>for<span class=\"token punctuation\">(</span>i<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>i<span class=\"token operator\"><</span><span class=\"token number\">9</span><span class=\"token punctuation\">;</span>i++<span class=\"token punctuation\">)</span> db.t2.insert<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"x\"</span>:i<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote _id:ObjectId(64f7f23fff2142d2a2445370),x:8=\"\" _id:ObjectId(64f7f23fff2142d2a244536f),x:7=\"\">\n<p>db.t2.find();<br>\n{ “_id” : ObjectId(“64f7f23fff2142d2a244536a”), “x” : 2 }<br>\n{ “_id” : ObjectId(“64f7f23fff2142d2a244536b”), “x” : 3 }<br>\n{ “_id” : ObjectId(“64f7f23fff2142d2a244536c”), “x” : 4 }<br>\n{ “_id” : ObjectId(“64f7f23fff2142d2a244536d”), “x” : 5 }<br>\n{ “_id” : ObjectId(“64f7f23fff2142d2a244536e”), “x” : 6 }<br>\n</p>\n</blockquote>\n<h3 id=\"结论\"><a class=\"markdownIt-Anchor\" href=\"#结论\">#</a> 结论</h3>\n<p><strong>前面的数据被顶掉了</strong></p>\n<h2 id=\"pretty美化输出\"><a class=\"markdownIt-Anchor\" href=\"#pretty美化输出\">#</a> pretty 美化输出</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db.t3.insert<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"_id\"</span>:1,<span class=\"token string\">\"phone\"</span>:<span class=\"token punctuation\">{</span><span class=\"token string\">\"hemophone\"</span><span class=\"token builtin class-name\">:</span><span class=\"token string\">\"8617118\"</span>,<span class=\"token string\">\"mobilephone\"</span><span class=\"token builtin class-name\">:</span><span class=\"token string\">\"18643079329\"</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><blockquote>\n<p>db.t3.find().pretty();<br>\n{<br>\n“_id” : 1,<br>\n“phone” : {<br>\n“hemophone” : “8617118”,<br>\n“mobilephone” : “18643079329”<br>\n}<br>\n}</p>\n</blockquote>\n<h2 id=\"管道机制\"><a class=\"markdownIt-Anchor\" href=\"#管道机制\">#</a> 管道机制</h2>\n<p _id:1,name:iphone8,price:3000,type:电子通信=\"\"></p>\n",
"tags": [
"MongoDB",
"MongoDB"
]
},
{
"id": "https://735690757.github.io/Operate-system/03OS/",
"url": "https://735690757.github.io/Operate-system/03OS/",
"title": "进程同步问题",
"date_published": "2023-09-04T07:50:00.000Z",
"content_html": "<h1 id=\"生产者-消费者问题\"><a class=\"markdownIt-Anchor\" href=\"#生产者-消费者问题\">#</a> 生产者 - 消费者问题</h1>\n<p>在进程同步中第一个问题就是生产者 - 消费者问题,首先我们利用记录型信号来分析这个问题。</p>\n<p>好好好,我们直接伪代码解析!</p>\n<p><strong>解释在行代码的上方</strong></p>\n<figure class=\"highlight c\"><figcaption data-lang=\"c\"><span>详细伪代码</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token comment\">//in 代表下一个要写入的位置,out 代表要读取的位置</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token keyword\">int</span> in <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>out <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token comment\">// 用于存储生产者生产的容器,可以理解为缓冲区</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre>item buffer<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token comment\">// 前两行不是重点,下面才是核心!!</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token comment\">//mutex 用于互斥访问共享资源,初值必须为 1(可以理解为锁)</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre><span class=\"token comment\">//empty 代表中转的容量,初值为最大承载容量,题里会给(可以是各种容器)</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token comment\">//full 是生产出的一种逻辑 / 实体的物质</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token comment\">// 总之不管是什么他是生产者生产出来的,一开始还没生产,full 初值为 0</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre>semaphore mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>empty <span class=\"token operator\">=</span> n<span class=\"token punctuation\">,</span>full <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre><span class=\"token comment\">// 生产者逻辑</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">producer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token comment\">//do-while 死循环,不断生产,配合消费者模拟程序并发</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token keyword\">do</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token comment\">// 生产一个产品</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> produce an item nextp<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token comment\">//wait 什么什么就是什么什么 “--”,比如这里 wait (empty) 就是 empty--</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token comment\">// 相当于空位置减一,申请一个缓冲区</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span>empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token comment\">// 相当于加锁,申请缓冲区的使用权</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token comment\">// 将产品放入缓冲区之中</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> buffer<span class=\"token punctuation\">[</span>in<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> nextp<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token comment\">// 下一个缓冲区的地址</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> in <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>in <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">%</span> n<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token comment\">//signal 什么什么就是什么什么 “++”,比如这里 signal (mutex) 就是 empty++</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token comment\">// 解锁,相当于释放权限</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token comment\">// 生产的东西数量加 1,也就是释放缓冲区</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>full<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token punctuation\">}</span><span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>true<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre><span class=\"token comment\">// 消费者逻辑</span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">consumer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> <span class=\"token comment\">//do-while 死循环,不断生消费,配合生产者模拟程序并发</span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre> <span class=\"token keyword\">do</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre> <span class=\"token comment\">// 消费者要消费一个物质,将生产者的生产的 full--</span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span>full<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"40\"></td><td><pre> <span class=\"token comment\">// 加锁,mutex--</span></pre></td></tr><tr><td data-num=\"41\"></td><td><pre> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"42\"></td><td><pre> <span class=\"token comment\">// 其实这里不用太深究,这里就是消费者从缓冲区拿走了一个生产者的生产的物质</span></pre></td></tr><tr><td data-num=\"43\"></td><td><pre> <span class=\"token comment\">// 从缓冲区中取出产品</span></pre></td></tr><tr><td data-num=\"44\"></td><td><pre> nextc <span class=\"token operator\">=</span> buffer<span class=\"token punctuation\">[</span>out<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"45\"></td><td><pre> <span class=\"token comment\">// 导向下一个缓冲区的地址</span></pre></td></tr><tr><td data-num=\"46\"></td><td><pre> out <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>out <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">%</span> n<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"47\"></td><td><pre> <span class=\"token comment\">// 解锁,mutex++</span></pre></td></tr><tr><td data-num=\"48\"></td><td><pre> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"49\"></td><td><pre> <span class=\"token comment\">// 消费者已经取走了,空位置 empty++</span></pre></td></tr><tr><td data-num=\"50\"></td><td><pre> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"51\"></td><td><pre> <span class=\"token comment\">// 消费者消费物质</span></pre></td></tr><tr><td data-num=\"52\"></td><td><pre> consume the item nextc<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"53\"></td><td><pre> <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></pre></td></tr><tr><td data-num=\"54\"></td><td><pre> <span class=\"token punctuation\">}</span><span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>true<span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"55\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"56\"></td><td><pre><span class=\"token keyword\">void</span> <span class=\"token function\">main</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"57\"></td><td><pre> cobegin</pre></td></tr><tr><td data-num=\"58\"></td><td><pre> <span class=\"token function\">producer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span><span class=\"token function\">consumer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"59\"></td><td><pre> coend</pre></td></tr><tr><td data-num=\"60\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><p>简单的写法:</p>\n<figure class=\"highlight py\"><figcaption data-lang=\"Python\"><span>简单伪代码</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre>Producer<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> Repeat</pre></td></tr><tr><td data-num=\"3\"></td><td><pre> 生产一个商品</pre></td></tr><tr><td data-num=\"4\"></td><td><pre> wait<span class=\"token punctuation\">(</span>empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> wait<span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> 将商品送至缓冲区<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> signal<span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> signal<span class=\"token punctuation\">(</span>full<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> Until false</pre></td></tr><tr><td data-num=\"10\"></td><td><pre></pre></td></tr><tr><td data-num=\"11\"></td><td><pre>Comsumer<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> Repeat</pre></td></tr><tr><td data-num=\"13\"></td><td><pre> wait<span class=\"token punctuation\">(</span>full<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> wait<span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> 从缓冲区取走一个物品</pre></td></tr><tr><td data-num=\"16\"></td><td><pre> singal<span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> signal<span class=\"token punctuation\">(</span>empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> Until false</pre></td></tr><tr><td data-num=\"19\"></td><td><pre></pre></td></tr><tr><td data-num=\"20\"></td><td><pre>Program main<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> empty<span class=\"token punctuation\">,</span>full<span class=\"token punctuation\">,</span>mutex<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> begin</pre></td></tr><tr><td data-num=\"23\"></td><td><pre> empty <span class=\"token operator\">=</span> n<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> full <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> cobegin</pre></td></tr><tr><td data-num=\"27\"></td><td><pre> producer<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>consumer<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> coend</pre></td></tr><tr><td data-num=\"29\"></td><td><pre> end</pre></td></tr></table></figure><h2 id=\"练习一下\"><a class=\"markdownIt-Anchor\" href=\"#练习一下\">#</a> 练习一下!</h2>\n<p>桌上有个能盛得下五个水果的空子。爸爸不停地向盘中放苹果或橘子,儿子不停地从盘中取出桔子享用,女儿不停地从盘中取出苹果享用。规定三人不能同时从盘子中取放水果。使用信号量实现爸爸、儿子和女儿这三个循环进程之间的同步。</p>\n<figure class=\"highlight c\"><figcaption data-lang=\"c\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre>empty <span class=\"token operator\">=</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span>orange <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>apple <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>mutex <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token function\">Dad</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span>empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> 将水果放入盘中<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>放了橘子<span class=\"token punctuation\">)</span> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>orange<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token keyword\">else</span> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>apple<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre></pre></td></tr><tr><td data-num=\"13\"></td><td><pre><span class=\"token function\">Son</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span>orange<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> 拿走一个桔子<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> 吃桔子<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre></pre></td></tr><tr><td data-num=\"24\"></td><td><pre><span class=\"token function\">Daughter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span>apple<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> 拿一个苹果<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>mutex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token function\">signal</span><span class=\"token punctuation\">(</span>empty<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> 吃苹果<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure>",
"tags": [
"操作系统",
"OS"
]
},
{
"id": "https://735690757.github.io/Linux/Linux01/",
"url": "https://735690757.github.io/Linux/Linux01/",
"title": "初见Linux",
"date_published": "2023-09-01T04:12:00.000Z",
"content_html": "<h1 id=\"初见linux\"><a class=\"markdownIt-Anchor\" href=\"#初见linux\">#</a> 初见 Linux</h1>\n<p>首先安装什么的就不讲了,这里先讲一下基础命令</p>\n<h1 id=\"简单命令\"><a class=\"markdownIt-Anchor\" href=\"#简单命令\">#</a> 简单命令</h1>\n<h2 id=\"who命令\"><a class=\"markdownIt-Anchor\" href=\"#who命令\">#</a> who 命令</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost ~<span class=\"token punctuation\">]</span>$ <span class=\"token function\">who</span> am i</pre></td></tr></table></figure><blockquote>\n<p>[karry@localhost ~]$ who am i<br>\nkarry pts/0 2023-09-01 10:26 (laptop-karry1107)</p>\n</blockquote>\n<h2 id=\"echo命令\"><a class=\"markdownIt-Anchor\" href=\"#echo命令\">#</a> echo 命令</h2>\n<p>这个命令是将内容输出到屏幕上</p>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost ~<span class=\"token punctuation\">]</span>$ <span class=\"token builtin class-name\">echo</span> Hello Karry.Liu</pre></td></tr></table></figure><blockquote>\n<p>[karry@localhost ~]$ echo Hello Karry.Liu<br>\nHello Karry.Liu</p>\n</blockquote>\n<h2 id=\"date命令\"><a class=\"markdownIt-Anchor\" href=\"#date命令\">#</a> date 命令</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost ~<span class=\"token punctuation\">]</span>$ <span class=\"token function\">date</span></pre></td></tr></table></figure><blockquote>\n<p>[karry@localhost ~]$ date<br>\n2023 年 09 月 01 日 星期五 10:32:23 PDT</p>\n</blockquote>\n<h2 id=\"cal命令\"><a class=\"markdownIt-Anchor\" href=\"#cal命令\">#</a> cal 命令</h2>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost ~<span class=\"token punctuation\">]</span>$ <span class=\"token function\">cal</span> <span class=\"token number\">9</span> <span class=\"token number\">2023</span></pre></td></tr></table></figure><blockquote>\n<p>[karry@localhost ~]$ cal 9 2023<br>\n 九月 2023<br>\n 日 一 二 三 四 五 六<br>\n 1 2<br>\n3 4 5 6 7 8 9<br>\n10 11 12 13 14 15 16<br>\n17 18 19 20 21 22 23<br>\n24 25 26 27 28 29 30</p>\n</blockquote>\n<h1 id=\"基础命令\"><a class=\"markdownIt-Anchor\" href=\"#基础命令\">#</a> 基础命令</h1>\n<h2 id=\"基础文件操作命令\"><a class=\"markdownIt-Anchor\" href=\"#基础文件操作命令\">#</a> 基础文件操作命令</h2>\n<h3 id=\"展示文件夹中的内容\"><a class=\"markdownIt-Anchor\" href=\"#展示文件夹中的内容\">#</a> 展示文件夹中的内容</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost ~<span class=\"token punctuation\">]</span>$ <span class=\"token function\">ls</span></pre></td></tr></table></figure><blockquote>\n<p>[karry@localhost ~]$ ls<br>\nDesktop Documents Downloads Music Pictures Public Templates Videos</p>\n</blockquote>\n<h3 id=\"进入退出文件夹\"><a class=\"markdownIt-Anchor\" href=\"#进入退出文件夹\">#</a> 进入 / 退出文件夹</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost ~<span class=\"token punctuation\">]</span>$ <span class=\"token builtin class-name\">cd</span> Desktop</pre></td></tr></table></figure><blockquote>\n<p>[karry@localhost ~]$ cd Desktop</p>\n<p>[karry@localhost Desktop]$</p>\n</blockquote>\n<h3 id=\"创建文件夹\"><a class=\"markdownIt-Anchor\" href=\"#创建文件夹\">#</a> 创建文件夹</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost Desktop<span class=\"token punctuation\">]</span>$ <span class=\"token function\">mkdir</span> LinuxHello</pre></td></tr></table></figure><blockquote>\n<p>[karry@localhost Desktop]$ ls<br>\nfirefox.desktop myFile test</p>\n<p>[karry@localhost Desktop]$ mkdir LinuxHello<br>\n[karry@localhost Desktop]$ ls<br>\nfirefox.desktop LiunxHello myFile test</p>\n</blockquote>\n<h3 id=\"创建一个文件\"><a class=\"markdownIt-Anchor\" href=\"#创建一个文件\">#</a> 创建一个文件</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost LinuxHello<span class=\"token punctuation\">]</span>$ <span class=\"token function\">touch</span> fistText.txt</pre></td></tr></table></figure><blockquote>\n<p>[karry@localhost Desktop]$ ls<br>\nfirefox.desktop LinuxHello myFile test<br>\n[karry@localhost Desktop]$ cd LinuxHello<br>\n[karry@localhost LinuxHello]$ touch fistText.txt<br>\n[karry@localhost LinuxHello]$ ls<br>\nfistText.txt</p>\n</blockquote>\n<h3 id=\"编辑文件\"><a class=\"markdownIt-Anchor\" href=\"#编辑文件\">#</a> 编辑文件</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost LinuxHello<span class=\"token punctuation\">]</span>$ <span class=\"token function\">touch</span> fistText.txt</pre></td></tr></table></figure><blockquote>\n<p>~<br>\n~<br>\n~<br>\n“fistText.txt” 0L, 0C</p>\n</blockquote>\n<p>按 <span class=\"kbd\">i</span> 进入插入模式</p>\n<blockquote>\n<p>~<br>\n~<br>\n~<br>\n– 插入 –</p>\n</blockquote>\n<p>现在可以编辑文件了!</p>\n<blockquote>\n<p>hi hi,这是我第一次学习 Linux!!!<br>\n我的名字是诗岸梦行舟<br>\n或者是 Karry.Liu<br>\n 让我们共同努力吧!!<br>\n~<br>\n~ – 插入 –</p>\n</blockquote>\n<p>按 <span class=\"kbd\">Esc</span> 退出插入模式</p>\n<p>按 <span class=\"kbd\">:</span>+ <span class=\"kbd\">w</span> 保存刚才所编辑的文件</p>\n<blockquote>\n<p>hi hi,这是我第一次学习 Linux!!!<br>\n我的名字是诗岸梦行舟<br>\n或者是 Karry.Liu<br>\n 让我们共同努力吧!!<br>\n~<br>\n“fistText.txt” 4L, 128C 已写入</p>\n</blockquote>\n<p>最后按 <span class=\"kbd\">:</span>+ <span class=\"kbd\">q</span> 退出 vi 编辑器</p>\n<blockquote>\n<p>~<br>\n~<br>\n:q</p>\n</blockquote>\n<h3 id=\"读文件内容\"><a class=\"markdownIt-Anchor\" href=\"#读文件内容\">#</a> 读文件内容</h3>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost LinuxHello<span class=\"token punctuation\">]</span>$ <span class=\"token function\">cat</span> fistText.txt</pre></td></tr></table></figure><blockquote>\n<p>[karry@localhost LinuxHello]$ cat fistText.txt<br>\nhi hi,这是我第一次学习 Linux!!!<br>\n我的名字是诗岸梦行舟<br>\n或者是 Karry.Liu<br>\n 让我们共同努力吧!!<br>\n[karry@localhost LinuxHello]$</p>\n</blockquote>\n<h1 id=\"使用g编译程序\"><a class=\"markdownIt-Anchor\" href=\"#使用g编译程序\">#</a> 使用 g++ 编译程序</h1>\n<ol start=\"0\">\n<li>\n<p>如果你还没有安装 g++ 编译器,请先安装</p>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token function\">sudo</span> yum <span class=\"token function\">install</span> gcc-c++ <span class=\"token function\">make</span></pre></td></tr></table></figure><p>安装需要一定时间,请耐心等待!</p>\n</li>\n<li>\n<p>进入指定目录,创建 cpp 文件。</p>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost C++<span class=\"token punctuation\">]</span>$ <span class=\"token function\">touch</span> firstApp.cpp</pre></td></tr></table></figure></li>\n<li>\n<p>使用 vi 指令编辑文件</p>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost C++<span class=\"token punctuation\">]</span>$ <span class=\"token function\">vi</span> firstApp.cpp</pre></td></tr></table></figure></li>\n<li>\n<p>按 <span class=\"kbd\">i</span> 进入插入模式,编辑程序</p>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token comment\">#include<iostream></span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre>using namespace std<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre>int <span class=\"token function-name function\">main</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> int <span class=\"token assign-left variable\">a</span><span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> int <span class=\"token assign-left variable\">b</span><span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> int <span class=\"token assign-left variable\">c</span><span class=\"token operator\">=</span>a+b<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> cout<span class=\"token operator\"><<</span><span class=\"token string\">\"计算结果为:\"</span><span class=\"token operator\"><<</span>a<span class=\"token operator\"><<</span><span class=\"token string\">\"+\"</span><span class=\"token operator\"><<</span>b<span class=\"token operator\"><<</span><span class=\"token string\">\"=\"</span><span class=\"token operator\"><<</span>c<span class=\"token operator\"><<</span>endl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token builtin class-name\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure></li>\n<li>\n<p>按 <span class=\"kbd\">Esc</span> 退出插入模式,按 <span class=\"kbd\">:</span>+ <span class=\"kbd\">w</span> 保存刚才所编辑的文件,最后按 <span class=\"kbd\">:</span>+ <span class=\"kbd\">q</span> 退出 vi 编辑器</p>\n</li>\n<li>\n<p>执行命令编译程序</p>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost C++<span class=\"token punctuation\">]</span>$ g++ <span class=\"token parameter variable\">-o</span> firstAppCompile firstApp.cpp</pre></td></tr></table></figure></li>\n<li>\n<p>运行输出结果</p>\n<figure class=\"highlight bash\"><figcaption data-lang=\"bash\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token punctuation\">[</span>karry@localhost C++<span class=\"token punctuation\">]</span>$ ./firstAppCompile</pre></td></tr></table></figure><blockquote>\n<p>[karry@localhost C++]$ ./firstAppCompile<br>\n 计算结果为:1+2=3<br>\n[karry@localhost C++]$</p>\n</blockquote>\n</li>\n</ol>\n",
"tags": [
"Linux",
"Linux"
]
},
{
"id": "https://735690757.github.io/Operate-system/02OS/",
"url": "https://735690757.github.io/Operate-system/02OS/",
"title": "进程与线程",
"date_published": "2023-08-31T11:50:00.000Z",
"content_html": "<h1 id=\"什么是进程与线程\"><a class=\"markdownIt-Anchor\" href=\"#什么是进程与线程\">#</a> 什么是进程与线程</h1>\n<p>进程(Process)和线程(Thread)是操作系统中的两个重要概念,用于管理和执行程序的执行单元。它们在多任务处理和并发执行中起着关键作用。</p>\n<h2 id=\"进程\"><a class=\"markdownIt-Anchor\" href=\"#进程\">#</a> 进程</h2>\n<p>进程是计算机系统中运行的程序的实例。每个进程都有<mark>自己的内存空间、代码和数据,以及与其他进程隔离的资源</mark>。进程可以看作是一个独立的执行环境,可以执行自己的任务。每个进程都有一个唯一的进程标识符(PID),用于区分和管理不同的进程。</p>\n<p><mark>一个进程可以包含多个线程,这些线程共享同一个进程的资源</mark>,如内存空间、文件句柄等。不同进程之间的通信相对复杂,通常需要使用进程间通信(IPC)机制,如管道、消息队列、共享内存等。</p>\n<h2 id=\"线程\"><a class=\"markdownIt-Anchor\" href=\"#线程\">#</a> 线程</h2>\n<p>线程是进程内的执行单元,一个进程可以包含多个线程。<mark>线程共享同一个进程的代码和数据,但每个线程拥有自己的栈空间和程序计数器</mark>。因为线程共享相同的内存空间,它们之间的通信和数据共享更加方便,但也需要适当的同步控制来避免竞态条件和数据不一致问题。</p>\n<p>多线程的使用可以实现并发执行,提高程序的响应速度和资源利用率。常见的线程使用场景包括图形界面应用程序中的响应性、多媒体处理、网络服务器等。</p>\n<h1 id=\"程序并发执行的特征\"><a class=\"markdownIt-Anchor\" href=\"#程序并发执行的特征\">#</a> 程序并发执行的特征</h1>\n<ol>\n<li><strong>间断性</strong>:并发程序之间相互制约</li>\n<li><strong>失去封闭性</strong>:多个程序共享全机资源,执行状态收外界因素影响</li>\n<li><strong>不可在现性</strong>:程序经过多次执行后,虽然其执行时的环境和初始条件都相同,但得到的结果却各不相同</li>\n</ol>\n<h1 id=\"进程的特性\"><a class=\"markdownIt-Anchor\" href=\"#进程的特性\">#</a> 进程的特性</h1>\n<ol>\n<li><strong>动态性</strong>(最基本的特征)</li>\n<li><strong>并发性</strong></li>\n<li><strong>独立性</strong></li>\n<li><strong>异步性</strong>:不可预知的速度</li>\n</ol>\n<h1 id=\"进程控制\"><a class=\"markdownIt-Anchor\" href=\"#进程控制\">#</a> 进程控制</h1>\n<p>一般包括以下几个方面:</p>\n<ol>\n<li>进程创建</li>\n<li>进程终止</li>\n<li>进程阻塞与唤醒</li>\n<li>进程挂起与激活</li>\n</ol>\n<h1 id=\"进程创建\"><a class=\"markdownIt-Anchor\" href=\"#进程创建\">#</a> 进程创建</h1>\n<p><span class=\"label success\">UNIX 下的进程创建 ——fork ()</span></p>\n<h2 id=\"消息机制\"><a class=\"markdownIt-Anchor\" href=\"#消息机制\">#</a> 消息机制</h2>\n<p>直接通信方式一一消息缓冲队列</p>\n<p>这是指发送进程利用 OS 所提供的发送命令,直接把消息发送给目标进程。此时,要求发送进程和接收进程都以显式方式提供对方的标识符。通常,系统提供下述两条通信命令 (原语):</p>\n<p><mark><strong>Send (Receiver, message): 发送一个消息给 Receiver</strong></mark></p>\n<p><mark><strong>Receive (Sender,message): 接收 Sender 发来的消息</strong></mark></p>\n<p>例如,原语 Send (P,m) 表示将消息 m, 发送给接收进程 P; 而原语 Receive (P,m) 则表示接收由 P 发来的消息 m。</p>\n<h1 id=\"进程通信\"><a class=\"markdownIt-Anchor\" href=\"#进程通信\">#</a> 进程通信</h1>\n<p>进程通信实例 ------ 管道通信方式 Pipe</p>\n<div class=\"note default\">\n<p>write (fd [1],buf,size); 将 buf 中长为 size 字符的消息送入 fd [1] 口</p>\n</div>\n<div class=\"note default\">\n<p>read (fd [0], buf’,size); 从 fd [O] 口读出 size 个字符置于 buf 中</p>\n</div>\n<h1 id=\"进程与线程的比较\"><a class=\"markdownIt-Anchor\" href=\"#进程与线程的比较\">#</a> 进程与线程的比较</h1>\n<h2 id=\"关于调度的基本单位\"><a class=\"markdownIt-Anchor\" href=\"#关于调度的基本单位\">#</a> 关于调度的基本单位</h2>\n<p>在传统 OS 中,拥有资源、独立调度和分配的基本单位都是进程。</p>\n<p>在引入线程的 OS 中,线程作为调度和分派的基本单位,进程作为拥有资源的基本单位。</p>\n<p>在同一进程中,线程的切换不会引起进程切换,在由一个进程中的线程切换到另一个进程中的线程时,将会引起进程切换。</p>\n<h2 id=\"并发性\"><a class=\"markdownIt-Anchor\" href=\"#并发性\">#</a> 并发性</h2>\n<p>在引入线程的操作系统中,不仅进程之间可以并发执行,而且在一个进程中的多个线程之间,也可并发执行</p>\n<h2 id=\"拥有资源\"><a class=\"markdownIt-Anchor\" href=\"#拥有资源\">#</a> 拥有资源</h2>\n<p>进程是系统中拥有资源的一个基本单位,它可以拥有资源</p>\n<p>线程本身不拥有系统资源,仅有一点保证独立运行的资源</p>\n<p>允许多个线程共享其隶属进程所拥有的资源</p>\n<h2 id=\"独立性\"><a class=\"markdownIt-Anchor\" href=\"#独立性\">#</a> 独立性</h2>\n<p>同一进程中的不同线程之间的独立性要比不同进程之间的独立性低得多</p>\n<h2 id=\"开销\"><a class=\"markdownIt-Anchor\" href=\"#开销\">#</a> 开销</h2>\n<p>在创建或撤消进程时,OS 所付出的开销将显著大于创建或撤消线程时的开销</p>\n<p>线程切换的代价远低于进程切换的代价。</p>\n<p>同一进程中的多个线程之间的同步和通信也比进程的简单</p>\n<h2 id=\"支持多处理机系统\"><a class=\"markdownIt-Anchor\" href=\"#支持多处理机系统\">#</a> 支持多处理机系统</h2>\n",
"tags": [
"操作系统",
"OS"
]
},
{
"id": "https://735690757.github.io/MongoDB/MongoDB01/",
"url": "https://735690757.github.io/MongoDB/MongoDB01/",
"title": "MongoDB的安装与初步使用(Windows平台)",
"date_published": "2023-08-30T04:20:00.000Z",
"content_html": "<h1 id=\"初见-mongodb\"><a class=\"markdownIt-Anchor\" href=\"#初见-mongodb\">#</a> 初见 MongoDB</h1>\n<h2 id=\"什么是-mongodb\"><a class=\"markdownIt-Anchor\" href=\"#什么是-mongodb\">#</a> 什么是 MongoDB?</h2>\n<p>MongoDB 是一个开源的、面向文档的 NoSQL 数据库管理系统。它与传统的关系型数据库(如 MySQL、PostgreSQL)不同,因为它不使用表格来存储数据,而是使用一种称为 "文档" 的数据结构来组织和存储数据。每个文档是一个包含键值对的数据结构,类似于 JSON 格式,这使得 MongoDB 非常适合存储具有不同结构的数据。</p>\n<p><img data-src=\"https://s2.loli.net/2023/08/30/iqxm3ufLjZ6XOSt.webp\" alt=\"MongoDB.png\"></p>\n<h1 id=\"mongodb-的安装与服务启动\"><a class=\"markdownIt-Anchor\" href=\"#mongodb-的安装与服务启动\">#</a> MongoDB 的安装与服务启动</h1>\n<h2 id=\"下载-mongodb-安装包\"><a class=\"markdownIt-Anchor\" href=\"#下载-mongodb-安装包\">#</a> 下载 MongoDB 安装包</h2>\n<p>访问<mark><span class=\"exturl\" data-url=\"aHR0cHM6Ly93d3cubW9uZ29kYi5jb20vZG93bmxvYWQtY2VudGVyI2NvbW11bml0eQ==\"> https://www.mongodb.com/download-center#community</span></mark><br>\n 或者点击下方连接</p>\n<div class=\"links\"><div class=\"item\" title=\"MongoDB\" style=\"--block-color:#e9546b;\"><span class=\"exturl image\" data-url=\"aHR0cHM6Ly93d3cubW9uZ29kYi5jb20vZG93bmxvYWQtY2VudGVyI2NvbW11bml0eQ==\" data-background-image=\"https://webimages.mongodb.com/_com_assets/cms/kuyjf3vea2hg34taa-horizontal_default_slate_blue.svg?auto=format%252Ccompress\"></span>\n <div class=\"info\">\n <span class=\"exturl title\" data-url=\"aHR0cHM6Ly93d3cubW9uZ29kYi5jb20vZG93bmxvYWQtY2VudGVyI2NvbW11bml0eQ==\">MogoDB</span>\n <p class=\"desc\">官方下载地址</p>\n </div></div></div>\n<p>下载载最新版本的 MongoDB 数据库。</p>\n<h2 id=\"mongodb-安装\"><a class=\"markdownIt-Anchor\" href=\"#mongodb-安装\">#</a> MongoDB 安装</h2>\n<ol>\n<li>双击刚刚下载的安装文件 (mongodb-XXXX-XXXX-signed.msi) 启动安装程序。</li>\n<li>单击【Next】按钮,进入 “End-User License Agreement” 界面</li>\n<li>勾选 “I accept the terms in the License Agreement” 选项,单击【Next】按钮进入 “Choose Setup Type” 界面,该界面中可选择安装类型</li>\n</ol>\n<p><span class=\"label primary\">Complete。此类型将安装所有程序功能,需占用较多的磁盘空间,建议大多数用户使用。</span><br>\n<span class=\"label primary\">Custom。此类型允许用户自行选择要安装的程序功能及安装位置,建议高级用户使用。</span></p>\n<ol start=\"4\">\n<li>MongoDB Compass 是 MongoDB 数据库的 GUI 管理系统,默认会选择安装,但是安装速度非常慢。</li>\n</ol>\n<p>值得一提的是,MongoDB 默认会将创建的数据库文件存储在 db 目录下,但是这个目录不会被主动创建,用户需要在 MongoDB 安装完成后手动创建 db 目录。在 “C:\\Program Files\\MongoDB\\Server\\4.0\\data\\” 目录下创建一个文件夹 db</p>\n<h1 id=\"配置\"><a class=\"markdownIt-Anchor\" href=\"#配置\">#</a> 配置</h1>\n<p>同样的我们也可以将 bin 目录配置到环境变量的 Path 中</p>\n<h1 id=\"启动-mongodb-服务启动与停止\"><a class=\"markdownIt-Anchor\" href=\"#启动-mongodb-服务启动与停止\">#</a> 启动 MongoDB 服务(启动与停止)</h1>\n<p>进入如图所示的目录输入<ins> net start MongoDB</ins> 启动服务,相应的输入<ins> net stop MongoDB</ins> 则为停止服务</p>\n<p><img data-src=\"https://s2.loli.net/2023/08/30/wWe7dPghAMOn31t.png\" alt=\"startStop.png\"></p>\n<h1 id=\"mongodb-基本命令\"><a class=\"markdownIt-Anchor\" href=\"#mongodb-基本命令\">#</a> MongoDB 基本命令</h1>\n<p>在 cmd 中输入 Mongo 进入 Mongo 的交互界面</p>\n<p>创建数据库:</p>\n<figure class=\"highlight mongodb\"><figcaption data-lang=\"mongodb\"><span>创建数据库</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre>use mydb</pre></td></tr></table></figure><p>展示数据库:</p>\n<figure class=\"highlight mongodb\"><figcaption data-lang=\"mongodb\"><span>展示据库</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre>show dbs</pre></td></tr></table></figure><p>删除数据库:</p>\n<figure class=\"highlight mongodb\"><figcaption data-lang=\"mongodb\"><span>删除数据库</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db<span class=\"token punctuation\">.</span><span class=\"token function\">dropDatabase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><p>创建集合:</p>\n<figure class=\"highlight mongodb\"><figcaption data-lang=\"mongodb\"><span>创建集合</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db<span class=\"token punctuation\">.</span><span class=\"token function\">createCollection</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"myCollection\"</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><p>插入数据:</p>\n<figure class=\"highlight mongodb\"><figcaption data-lang=\"mongodb\"><span>插入</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db<span class=\"token punctuation\">.</span>myCollection<span class=\"token punctuation\">.</span><span class=\"token function\">insert</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string-property property\">\"_id\"</span><span class=\"token operator\">:</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token string-property property\">\"name\"</span><span class=\"token operator\">:</span><span class=\"token string\">\"诗岸梦行舟\"</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><p>删除:</p>\n<figure class=\"highlight mongodb\"><figcaption data-lang=\"mongodb\"><span>删除</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db<span class=\"token punctuation\">.</span>myCollection<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string-property property\">\"_id\"</span><span class=\"token operator\">:</span><span class=\"token number\">1</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><p>更新:</p>\n<figure class=\"highlight mongodb\"><figcaption data-lang=\"mongodb\"><span>更新</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db<span class=\"token punctuation\">.</span>myCollection<span class=\"token punctuation\">.</span><span class=\"token function\">update</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string-property property\">\"_id\"</span><span class=\"token operator\">:</span><span class=\"token number\">1</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">{</span>$set<span class=\"token punctuation\">{</span><span class=\"token string-property property\">\"name\"</span><span class=\"token operator\">:</span><span class=\"token string\">\"Karry.Liu\"</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><p>查询所有:</p>\n<figure class=\"highlight mongodb\"><figcaption data-lang=\"mongodb\"><span>删除</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db<span class=\"token punctuation\">.</span>myCollection<span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure><p>指定查询:</p>\n<figure class=\"highlight mongodb\"><figcaption data-lang=\"mongodb\"><span>删除</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre>db<span class=\"token punctuation\">.</span>myCollection<span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string-property property\">\"_id\"</span><span class=\"token operator\">:</span><span class=\"token number\">1</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></pre></td></tr></table></figure>",
"tags": [
"MongoDB",
"MongoDB"
]
},
{
"id": "https://735690757.github.io/Operate-system/01OS/",
"url": "https://735690757.github.io/Operate-system/01OS/",
"title": "操作系统知识点阶段总结",
"date_published": "2023-08-28T23:50:00.000Z",
"content_html": "<h1 id=\"引论\"><a class=\"markdownIt-Anchor\" href=\"#引论\">#</a> 引论</h1>\n<h2 id=\"操作系统是什么\"><a class=\"markdownIt-Anchor\" href=\"#操作系统是什么\">#</a> <strong>操作系统是什么?</strong></h2>\n<p>操作系统是计算机系统中的核心软件之一,它是位于硬件和应用程序之间的一层软件,负责管理和控制计算机的硬件资源,并为应用程序提供一个运行环境。操作系统充当计算机系统的管理者,协调各种硬件和软件资源的分配和调度,以使计算机能够高效、可靠地运行。</p>\n<h2 id=\"为什么要操作系统\"><a class=\"markdownIt-Anchor\" href=\"#为什么要操作系统\">#</a> <strong>为什么要操作系统?</strong></h2>\n<p>操作系统的存在是为了解决计算机资源管理和用户程序执行的复杂性。它提供了一种抽象层,使应用程序开发人员不必直接与底层硬件进行交互,从而简化了应用程序的开发和维护。此外,操作系统还负责处理多任务管理、内存管理、文件系统管理、用户接口等,为用户和应用程序提供了一个友好且高效的计算环境。</p>\n<h2 id=\"操作系统的特征是什么\"><a class=\"markdownIt-Anchor\" href=\"#操作系统的特征是什么\">#</a> <strong>操作系统的特征是什么?</strong></h2>\n<p>操作系统具有以下几个主要特征:</p>\n<ol>\n<li>\n<p><strong>并发(Concurrency):</strong> 能够同时处理多个任务或程序,使多个程序可以在同一台计算机上交替执行。</p>\n<p><mark>(并发:同一时间段 并行:同一时刻)</mark></p>\n</li>\n<li>\n<p><strong>共享(Sharing):</strong> 多个用户和应用程序可以同时访问计算机的资源,如内存、处理器、文件等。</p>\n<p><span class=\"label info\">操作系统的最基本特征:并发与共享</span></p>\n</li>\n<li>\n<p><strong>虚拟(Virtualization):</strong> 操作系统可以为每个应用程序提供一种虚拟的环境,使其感觉自己独占了计算机资源。</p>\n</li>\n<li>\n<p><strong>异步(asynchronous):</strong> 异步特性指的是操作系统允许某些任务在进行的过程中,不必等待前一个任务的完成,而可以继续执行其他任务。<mark>(存在不确定性)</mark></p>\n<p><span class=\"label success\">✔️操作系统的基本特征:并发、共享、虚拟、异步</span></p>\n</li>\n<li>\n<p><strong>抽象(Abstraction):</strong> 操作系统通过抽象化硬件和软件资源,为应用程序提供一个更简单、一致的编程接口。</p>\n</li>\n<li>\n<p><strong>持久性(Persistence):</strong> 数据和程序可以被存储在持久性存储设备中,并在计算机关闭后保留下来。</p>\n</li>\n<li>\n<p><strong>处理器管理(Processor Management):</strong> 分配和管理处理器的时间片,以便多个任务可以轮流执行。</p>\n</li>\n<li>\n<p><strong>内存管理(Memory Management):</strong> 管理计算机的内存资源,包括分配、释放、虚拟内存等。</p>\n</li>\n<li>\n<p><strong>文件系统管理(File System Management):</strong> 管理文件的存储、组织、检索和保护。</p>\n</li>\n<li>\n<p><strong>设备管理(Device Management):</strong> 管理输入输出设备,使应用程序能够与设备进行交互。</p>\n</li>\n</ol>\n<h2 id=\"实时操作系统和分时操作系统\"><a class=\"markdownIt-Anchor\" href=\"#实时操作系统和分时操作系统\">#</a> 实时操作系统和分时操作系统?</h2>\n<p>实时操作系统(Real-time Operating System,RTOS)和分时操作系统(Time-sharing Operating System)是两种不同类型的操作系统,用于满足不同应用场景下的需求。</p>\n<h3 id=\"实时操作系统rtos\"><a class=\"markdownIt-Anchor\" href=\"#实时操作系统rtos\">#</a> <strong>实时操作系统(RTOS):</strong></h3>\n<p>实时操作系统是专门设计用于处理实时任务的操作系统。实时任务是具有严格时间要求的任务,可以分为硬实时和软实时任务。硬实时任务要求任务必须在严格的时间限制内完成,否则会导致系统错误。软实时任务也有时间要求,但对于这类任务,如果错过了截止日期,系统不会崩溃,但会影响任务的结果的实用性。</p>\n<p>RTOS 致力于确保任务能够按照特定的时间要求得到执行。它通常采用优先级调度策略,确保高优先级的实时任务能够在预定的时间内得到执行。</p>\n<h3 id=\"分时操作系统time-sharing-operating-system\"><a class=\"markdownIt-Anchor\" href=\"#分时操作系统time-sharing-operating-system\">#</a> <strong>分时操作系统(Time-sharing Operating System):</strong></h3>\n<p>分时操作系统旨在支持多用户的共享计算机系统。它允许多个用户通过终端或其他用户界面同时访问系统,每个用户似乎都在独占地使用计算机资源。分时操作系统通过分配时间片(时间片轮转)来在多个任务之间切换,每个任务在时间片结束前都能得到一段时间的执行。</p>\n<p>分时操作系统的目标是实现多任务的并发执行,使用户能够在几乎同时使用计算机资源,这样可以提高资源利用率和用户体验。</p>\n<p><span class=\"label info\">分时操作系统特征:多路性、独立性、及时性、交互性。详细解释:P10</span></p>\n<h2 id=\"单道批处理系统和多道批处理系统\"><a class=\"markdownIt-Anchor\" href=\"#单道批处理系统和多道批处理系统\">#</a> 单道批处理系统和多道批处理系统?</h2>\n<p>单道批处理系统(Single Batch Processing System)和多道批处理系统(Multi-Batch Processing System)是两种不同的操作系统工作方式,用于管理和执行计算机中的多个任务。</p>\n<h3 id=\"单道批处理系统\"><a class=\"markdownIt-Anchor\" href=\"#单道批处理系统\">#</a> <strong>单道批处理系统:</strong></h3>\n<p>单道批处理系统是早期计算机操作系统的一种。在这种系统中,计算机只能处理一道程序,也就是一个任务,每次只有一个任务在运行。当一个任务执行完成后,才能加载并执行下一个任务。这种系统对于用户和程序员来说,操作不够灵活,因为他们必须等待当前任务执行完成才能继续工作。</p>\n<p><span class=\"label danger\">💔单道批处理系统的缺点:系统中的的资源得不到充分利用!</span></p>\n<p><span class=\"label warning\">✍️注意注意!!!单道批处理系统无并发,不能称之为 OS!!!</span></p>\n<h3 id=\"多道批处理系统\"><a class=\"markdownIt-Anchor\" href=\"#多道批处理系统\">#</a> <strong>多道批处理系统:</strong></h3>\n<p>多道批处理系统是在单道批处理系统的基础上发展而来的。这种系统允许计算机在内存中同时加载和管理多个任务,而不需要等待前一个任务的完成。多道批处理系统将内存分割成多个区域,每个区域可以加载一个任务的代码和数据。操作系统会在任务之间进行切换,以实现多个任务的并发执行。这种方式提高了计算机的资源利用率和效率。</p>\n<h2 id=\"os-的类型\"><a class=\"markdownIt-Anchor\" href=\"#os-的类型\">#</a> OS 的类型?</h2>\n<ol>\n<li><strong>多道批处理系统(Multi-programming Batch System):</strong> 多道批处理系统是一种操作系统,允许多个任务(作业)在内存中同时存在,但每个任务的执行是按照一定的调度策略轮流进行的。它旨在提高计算机的资源利用率,通过在任务之间切换以避免 CPU 空闲。每个任务通常独立运行,不需要用户干预。这种系统适用于大量任务需要批量处理,例如批量数据处理任务。</li>\n<li><strong>分时系统(Time-sharing System):</strong> 分时系统允许多个用户通过终端或用户界面同时访问计算机,每个用户似乎都在独占地使用计算机资源。系统通过快速的任务切换(时间片轮转)实现用户之间的并发执行,每个用户能够迅速交互并使用计算机。分时系统适用于多用户、交互式的环境,如图形用户界面和终端。</li>\n<li><strong>实时系统(Real-time System):</strong> 实时系统是专门设计用于处理实时任务的操作系统。实时任务具有严格的时间要求,可以分为硬实时和软实时。硬实时任务要求任务必须在严格的时间限制内完成,否则会导致系统错误。软实时任务也有时间要求,但错过截止日期不会导致系统错误。实时系统旨在确保任务能够按照特定的时间要求得到执行,适用于需要在严格时间约束下运行的应用,如飞行控制系统和医疗设备。</li>\n</ol>\n<h2 id=\"操作系统能干什么\"><a class=\"markdownIt-Anchor\" href=\"#操作系统能干什么\">#</a> <strong>操作系统能干什么?</strong></h2>\n<p>操作系统的主要任务包括:</p>\n<ul>\n<li>管理计算机的硬件资源,如处理器、内存、硬盘、网络接口等。</li>\n<li>提供多任务管理,使多个应用程序可以同时运行。</li>\n<li>提供虚拟化,将物理资源抽象为多个虚拟资源,提供更好的资源利用率。</li>\n<li>管理文件系统,让用户能够创建、存储、组织和检索文件。</li>\n<li>处理输入输出,使用户和应用程序能够与外部设备进行交互。</li>\n<li>提供用户界面,让用户能够与计算机进行交互,如命令行界面或图形用户界面。</li>\n</ul>\n<h2 id=\"操作系统有哪些\"><a class=\"markdownIt-Anchor\" href=\"#操作系统有哪些\">#</a> <strong>操作系统有哪些?</strong></h2>\n<p>常见的操作系统包括:</p>\n<ul>\n<li>Windows:微软开发的操作系统系列,如 Windows 10、Windows 11 等。</li>\n<li>macOS:苹果公司开发的操作系统,用于 Mac 电脑。</li>\n<li>Linux:一种开源的 Unix-like 操作系统,有许多不同的发行版,如 Ubuntu、Fedora、Debian 等。</li>\n<li>Unix:一种经典的多用户多任务操作系统,影响了许多其他操作系统的设计。</li>\n<li>Android:基于 Linux 内核的移动设备操作系统,由谷歌开发。</li>\n<li>iOS:苹果公司用于 iPhone 和 iPad 等移动设备的操作系统。</li>\n<li>OpenHarmony:分布式操作系统,由华为公司开发。</li>\n</ul>\n<h2 id=\"操作系统的新发展\"><a class=\"markdownIt-Anchor\" href=\"#操作系统的新发展\">#</a> <strong>操作系统的新发展?</strong></h2>\n<p>操作系统领域一直在不断发展演进。一些新的趋势和发展包括:</p>\n<ul>\n<li><strong>云操作系统:</strong> 针对云计算环境的操作系统,如 Google 的 Chrome OS 和微软的 Azure Sphere。</li>\n<li><strong>嵌入式操作系统:</strong> 用于嵌入式系统,如物联网设备和嵌入式控制器的操作系统,如 FreeRTOS 和 Zephyr。</li>\n<li><strong>容器化和微服务:</strong> 使用容器技术(如 Docker)和微服务架构的操作系统,以支持更高效的应用程序部署和管理。</li>\n<li><strong>实时操作系统(RTOS):</strong> 针对实时应用程序的操作系统,要求任务能够在严格的时间限制内得到执行。</li>\n<li><strong>量子操作系统:</strong> 随着量子计算的发展,涉及管理量子资源和运行量子算法的操作系统正在探索中。</li>\n</ul>\n<p>这些都只是操作系统领域的一部分发展趋势,操作系统将继续适应新的硬件和应用场景,以满足不断变化的需求。</p>\n<h2 id=\"简单总结\"><a class=\"markdownIt-Anchor\" href=\"#简单总结\">#</a> 简单总结!</h2>\n<p>操作系统的定义可归纳为:操作系统是控制和管理计算机系统内各种硬件和软件资源、合理组织计算机工作流程的系统软件 (或程序集合),是用户与计算机之间的接口。</p>\n<p>操作系统是什么?<mark>是核心系统软件</mark><br>\n操作系统管什么?<mark>控制和管理系统内各资源</mark><br>\n操作系统有何用?<mark>扩充硬件功能,方便用户使用</mark></p>\n<h2 id=\"练习\"><a class=\"markdownIt-Anchor\" href=\"#练习\">#</a> 练习</h2>\n<ol>\n<li class=\"quiz\">\n<p>一个作业第一次执行时用了 5 分钟,而第二次执行时用了 6 分钟,这说明了操作系统的 <span class=\"gap\"></span> 特点。</p>\n<ul class=\"options\">\n<li>并发</li>\n<li>共享</li>\n<li>虚拟</li>\n<li class=\"correct\">异步</li>\n</ul>\n<details class=\"primary\"><summary>解释</summary><div>\n<ul>\n<li>异步存在时间不确定性</li>\n</ul>\n</div></details>\n</li>\n<li class=\"quiz\">\n<p>操作系统的最基本的两个特征是资源共享和 <span class=\"gap\"></span> 。</p>\n<ul class=\"options\">\n<li>多道程序设计</li>\n<li class=\"correct\">程序的并发执行</li>\n<li>中断</li>\n<li>程序顺序执行</li>\n</ul>\n</li>\n<li class=\"quiz\">\n<p>单道批处理系统的主要缺点是 <span class=\"gap\"></span> 。</p>\n<ul class=\"options\">\n<li class=\"correct\">CPU 利用率不高</li>\n<li>失去了交互性</li>\n<li>不具备并行性</li>\n<li>以上都不是</li>\n</ul>\n</li>\n</ol>\n<details class=\"primary\"><summary>解释</summary><div>\n<ul>\n<li>实际上 ABC 都是他的缺点,但是 <mark>CPU / 资源利用率不高</mark>是他的主要缺点</li>\n</ul>\n</div></details>\n<ol start=\"4\">\n<li class=\"quiz false\">\n<p>采用多道程序设计的系统中,系统中的程序道数越多,系统的效率越高。</p>\n</li>\n<li class=\"quiz false\">\n<p>通常将 CPU 模式分为内核态 (核心态) 和用户态,这样做的目的是为了提高运行速度。</p>\n</li>\n<li class=\"quiz true\">\n<p>操作系统内核能使用特权指令。</p>\n</li>\n</ol>\n<details class=\"info\"><summary>解析</summary><div>\n<ol start=\"4\">\n<li>程序道数多多会导致每个程序分得的内存不够,很多程序所需的数据和代码要临时从磁盘调入内存系统会频繁的进行 I/O,使得系统效率下降!</li>\n<li>是为了提高安全性 ==(双重工作模式 P20)==</li>\n<li>确实对</li>\n</ol>\n</div></details>\n<h1 id=\"进程\"><a class=\"markdownIt-Anchor\" href=\"#进程\">#</a> 进程</h1>\n<h2 id=\"进程的几个基本状态\"><a class=\"markdownIt-Anchor\" href=\"#进程的几个基本状态\">#</a> 进程的几个基本状态</h2>\n<ol>\n<li><strong>就绪状态(Ready):</strong> 进程已获得除处理器外的所需资源,等待分配处理器资源;只要分配了处理器进程就可执行。就绪进程可以按多个优先级来划分队列。例如,当一个进程由于时间片用完而进入就绪状态时,排入低优先级队列;当进程由 I/O 操作完成而进入就绪状态时,排入高优先级队列.</li>\n<li><strong>运行状态 (Running):</strong> 进程占用处理器资源;处于此状态的进程的数目小于等于处理器的数目。在没有其他进程可以执行时 (如所有进程都在阻塞状态), 通常会自动执行系统的空闲进程.</li>\n<li><strong>阻塞状态 (Blocked):</strong> 由于进程等待某种条件(如 I/O 操作或进程同步), 在条件满足之前无法继续执行。该事件发生前即使把处理机分配给该进程,也无法运行.</li>\n</ol>\n<p><img data-src=\"https://s2.loli.net/2023/08/29/X8stjGRqdnJPr26.jpg\" alt=\"osStateTransition.jpg\"></p>\n<h2 id=\"名词解释\"><a class=\"markdownIt-Anchor\" href=\"#名词解释\">#</a> 名词解释</h2>\n<p><strong>挂起:</strong> 从内存挂至外存</p>\n<p><strong>时间片:</strong> 程序执行的一段时间</p>\n<p><strong>阻塞:</strong> 发生 I/O 或者其他事件进入阻塞状态</p>\n<h2 id=\"扩展状态考研\"><a class=\"markdownIt-Anchor\" href=\"#扩展状态考研\">#</a> 扩展状态(考研)</h2>\n<p><img data-src=\"https://s2.loli.net/2023/08/29/RDfm3M4nLPioruT.jpg\" alt=\"osStateTransitionExtend.jpg\"></p>\n<h2 id=\"练习-2\"><a class=\"markdownIt-Anchor\" href=\"#练习-2\">#</a> 练习</h2>\n<ol>\n<li class=\"quiz\">\n<p>当 <span class=\"gap\"></span> 时,进程从执行状态转变为就绪状态。</p>\n<ul class=\"options\">\n<li>进程被调度程序选中</li>\n<li class=\"correct\">时间片到</li>\n<li>等待某一事件</li>\n<li>等待的事件发生</li>\n</ul>\n</li>\n<li class=\"quiz\">\n<p>在进程状态转换时,下列 <span class=\"gap\"></span> 转换是不可能发生的。</p>\n<ul class=\"options\">\n<li>就绪态 一 > 运行态</li>\n<li>运行态 一 > 就绪态</li>\n<li>运行态 一 > 阻塞态</li>\n<li class=\"correct\">阻塞态 一 > 运行态</li>\n</ul>\n</li>\n<li class=\"quiz\">\n<p>进程和程序的本质区别是 <span class=\"gap\"></span></p>\n<ul class=\"options\">\n<li class=\"correct\">前者是动态的,后者是静态的</li>\n<li>前者存储在内存,后者存储在外存</li>\n<li>前者在一个文件中,后者在多个文件中</li>\n<li>前者分时使用 CPU,后者独占 CPU</li>\n</ul>\n</li>\n<li class=\"quiz\">\n<p>程序运行时独占系统资源,只有程序本身能改变系统资源状态,这是指 <span class=\"gap\"></span></p>\n<ul class=\"options\">\n<li>程序顺序执行的再现性</li>\n<li>并发程序失去再现性</li>\n<li>并发程序失夫封闭性</li>\n<li class=\"correct\">程序顺序执行时的封闭性</li>\n</ul>\n</li>\n<li class=\"quiz false\">\n<p>不同的进程必然对应不同的程序。</p>\n</li>\n<li class=\"quiz true\">\n<p>进程状态的转换是由操作系统完成的,对用户是透明的。</p>\n</li>\n</ol>\n<h2 id=\"进程控制块process-control-blockpcb\"><a class=\"markdownIt-Anchor\" href=\"#进程控制块process-control-blockpcb\">#</a> 进程控制块(Process Control Block,PCB)</h2>\n<p>每个正在运行或等待运行的进程都有一个对应的 PCB,它包含了进程的各种属性、状态以及与其相关的控制信息。PCB 是操作系统内部用于实现进程管理的重要数据结构之一。</p>\n<ol>\n<li>进程状态(Process State):表示进程的当前状态,如运行、就绪、阻塞等。操作系统根据进程状态来进行调度和管理。</li>\n<li>程序计数器(Program Counter):指向进程当前执行的指令的地址,用于恢复进程的执行状态。</li>\n<li>寄存器(Registers):保存进程的寄存器值,包括通用寄存器、程序状态寄存器等。</li>\n<li>进程优先级(Process Priority):用于调度器决定哪个进程将获得 CPU 执行时间。</li>\n<li>进程标识符(Process ID):唯一标识一个进程的数字或字符串。</li>\n<li>进程所拥有的资源信息:如打开的文件列表、分配的内存空间等。</li>\n<li>进程的父子关系:记录进程之间的层次结构,用于实现进程间的通信和协作。</li>\n<li>进程的各种统计信息:如运行时间、等待时间等,用于性能分析和调优。</li>\n</ol>\n<p>PCB 的存在使得操作系统可以高效地进行进程的切换、调度、挂起、恢复等操作。当操作系统需要切换到另一个进程时,它可以保存当前进程的状态信息到其对应的 PCB,然后加载新进程的状态信息,从而实现进程切换。这种切换是操作系统多任务处理的基础,使得多个进程可以在单个 CPU 上共享时间,并且实现了对系统资源的合理分配和利用。</p>\n<h2 id=\"pcb-组织方式\"><a class=\"markdownIt-Anchor\" href=\"#pcb-组织方式\">#</a> PCB 组织方式</h2>\n<p><img data-src=\"https://s2.loli.net/2023/08/29/An6JckEslPQOC49.jpg\" alt=\"PCB1.jpg\"></p>\n<p><img data-src=\"https://s2.loli.net/2023/08/29/pO4wvVrkN1DdMo8.jpg\" alt=\"PCB2.jpg\"></p>\n<p><img data-src=\"https://s2.loli.net/2023/08/29/cr1Bm69ez7uKgUZ.jpg\" alt=\"POB3.jpg\"></p>\n<h2 id=\"练习-3\"><a class=\"markdownIt-Anchor\" href=\"#练习-3\">#</a> 练习</h2>\n<ol>\n<li class=\"quiz true\">\n<p>在 PCB 中可以直接或间接找到有关该进程的所有信息。</p>\n</li>\n<li class=\"quiz true\">\n<p>进程由 PCB 和其执行的程序、数据所组成</p>\n</li>\n</ol>\n",
"tags": [
"操作系统",
"OS"
]
},
{
"id": "https://735690757.github.io/experience/SSM01/",
"url": "https://735690757.github.io/experience/SSM01/",
"title": "SSM框架整合",
"date_published": "2023-08-15T03:00:00.000Z",
"content_html": "<h1 id=\"是什么ssm\"><a class=\"markdownIt-Anchor\" href=\"#是什么ssm\">#</a> 是什么 SSM</h1>\n<p>SSM 是三个框架的简写,本别是<strong> Spring,SpringMVC,Mybatis</strong>,这三个框架作为 JavaWeb 强有力的支撑件,极大地提高了开发效率,降低了维护成本,是 Java 程序员学习 Web 技术的<strong>必经之路</strong>(至少现在是这样)</p>\n<p>在此之前,我希望你能熟练掌握,额,哪怕不熟练也要了解 Web 部分的老祖:<strong>请求,响应以及 Servlet 技术</strong>,这些技术能帮助你更好、更快、更流畅的掌握 SSM 技术。</p>\n<p>其次本文主要讲解 SSM 整合的相关细节,<strong>并不会深入讲解 Spring,SpringMVC,Mybatis 每个框架的知识</strong>,希望大家在看本文之前能了解 Spring,SpringMVC,Mybatis 单个框架的使用方法。</p>\n<h1 id=\"整合开始\"><a class=\"markdownIt-Anchor\" href=\"#整合开始\">#</a> 整合开始</h1>\n<p>首先我先放出最终的整合状态,其实也不一定非要按照我这样来做。</p>\n<table>\n<thead>\n<tr>\n<th><img data-src=\"https://s2.loli.net/2023/08/27/oOYkfcqT4sChgZ8.png\" alt=\"1.png\"></th>\n<th style=\"text-align:left\">bean 包:大多数的实体类<br /><br />config 包:整合的核心配置类<br /><br />controller 包:外部控制器暴露点<br /><br />mapper 包:Mybiats SQL 标准化<br /><br />service 包:业务逻辑,包含接口以及实现<br /><br />resource 包:资源文件、配置文件<br /><br />webapp:前端资源</th>\n</tr>\n</thead>\n</table>\n<p>那么接下来我将带着大家一步一步的来做,从创建项目到最终完成整合。</p>\n<h2 id=\"创建项目maven构建方式\"><a class=\"markdownIt-Anchor\" href=\"#创建项目maven构建方式\">#</a> 创建项目(Maven 构建方式)</h2>\n<p>选择新建一个项目(或模块),选择<strong> Maven Archetype 形式</strong>创建,我给他命名叫做 SSM_demo。</p>\n<p>JDK:1.8(Java 8)</p>\n<p>Archetype:选择最后以<strong> webapp 结尾</strong>的,这是一个创建模板</p>\n<p>组 ID:公司域名反写</p>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/8AHEv3qyFMLpZi9.png\" alt=\"2.png\"></p>\n<h2 id=\"创建包结构\"><a class=\"markdownIt-Anchor\" href=\"#创建包结构\">#</a> 创建包结构</h2>\n<p>在 main 目录下创建 java 目录和必要的包结构</p>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/wdcBFt4Vl7auSj5.png\" alt=\"3.png\"></p>\n<h2 id=\"依赖导入-必要启动配置\"><a class=\"markdownIt-Anchor\" href=\"#依赖导入-必要启动配置\">#</a> 依赖导入、必要启动配置</h2>\n<p>我们需要在 pom.xml 文件下导入我们 SSM 所需要的依赖,并配置必要的启动项。</p>\n<h3 id=\"导入详解\"><a class=\"markdownIt-Anchor\" href=\"#导入详解\">#</a> 导入详解</h3>\n<p><strong>第一步:导包</strong></p>\n<p>需要思考我们需要什么依赖:</p>\n<p><strong><ins class=\"wavy\">junit</ins></strong>:单元测试。</p>\n<p><strong><ins class=\"wavy\">spring-webmvc</ins></strong>:整个依赖就比较强大了她不仅包含了 SpringMVC 的部分也包含了 Spring-Context 部分,其实也不难理解,因为 SpringMVC 是基于 Spring 开发的,那也就必然包含了 Spring 框架的部分。</p>\n<p>至此我们还剩下数据库的部分,我们继续将其填充完整。</p>\n<p><strong><ins class=\"wavy\">Mybatis</ins></strong>:这个是 Mybatis 的核心依赖。</p>\n<p><strong><ins class=\"wavy\">mybatis-spring</ins></strong>:整个是将 Mybatis 与 Spring 进行整合。</p>\n<p><strong><ins class=\"wavy\">spring-jdbc</ins></strong>:简化 Java 应用程序与数据库之间的交互,Spring JDBC 是 MyBatis-Spring 的底层依赖,提供了连接管理、事务管理等基础功能。</p>\n<p><strong><ins class=\"wavy\">mysql-connector-java</ins></strong>:这个是 MySQL 的驱动依赖。</p>\n<p><strong><ins class=\"wavy\">druid</ins></strong>:数据库连接池。</p>\n<p><strong><ins class=\"wavy\">servlet-api</ins></strong>:Spring MVC 架构是基于 Servlet 规范的。它使用 Servlet API 来处理和分发 Web 请求,以及与 Web 容器进行交互。</p>\n<p><strong><ins class=\"wavy\">jackson-databind</ins></strong>:用于在 Java 对象和 JSON 数据之间进行序列化(对象到 JSON)和反序列化(JSON 到对象)的核心部分。</p>\n<figure class=\"highlight xml\"><figcaption data-lang=\"XML\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependencies</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>junit<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>junit<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>4.13.2<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>scope</span><span class=\"token punctuation\">></span></span>test<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>scope</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>org.springframework<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>spring-webmvc<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>5.2.10.RELEASE<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>org.mybatis<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>mybatis<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>3.5.9<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>org.mybatis<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>mybatis-spring<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>2.0.7<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>org.springframework<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>spring-jdbc<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>6.0.6<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>mysql<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>mysql-connector-java<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>8.0.31<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>javax.servlet<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>servlet-api<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>2.5<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>scope</span><span class=\"token punctuation\">></span></span>provided<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>scope</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"40\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>com.fasterxml.jackson.core<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"41\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>jackson-databind<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"42\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>2.13.4<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"43\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"44\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependencies</span><span class=\"token punctuation\">></span></span></pre></td></tr></table></figure><p>一定要为我们的 servlet-api 配置作用域为 provided,<strong>这是非常大的一个坑点</strong>!!!</p>\n<p>如果您不将 <code>servlet-api</code> 的作用域设置为 <code>provided</code> ,而是将其作用域设置为默认的 <code>compile</code> ,则可能会导致以下问题和影响:</p>\n<ol>\n<li><strong>冲突问题:</strong> 如果您的应用程序包含了自己的 Servlet API 实现(例如 jar 包),而 Web 容器也提供了自己的实现,可能会导致冲突和不稳定性。</li>\n<li><strong>版本不一致:</strong> 不同的 Web 容器可能使用不同版本的 Servlet API,如果您将 API 包含在应用程序中,可能会导致版本不一致的问题。</li>\n<li><strong>应用程序大小增加:</strong> 将 Servlet API 包含在应用程序中会增加应用程序的大小,尽管这在绝大多数情况下可能不会对性能产生明显影响,但仍然会浪费一些资源。</li>\n<li><strong>维护困难:</strong> 如果您在多个项目中重复地包含 Servlet API,可能会导致维护上的困难,特别是在更新版本或切换到不同的 Web 容器时。</li>\n</ol>\n<figure class=\"highlight xml\"><figcaption data-lang=\"XML\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>scope</span><span class=\"token punctuation\">></span></span>provided<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>scope</span><span class=\"token punctuation\">></span></span></pre></td></tr></table></figure><p><strong>第二步:启动配置</strong></p>\n<p>在这里你可以选择外挂 Tomcat 和 Maven 插件的两种启动方式,在这里我选择插件法,因为外挂启动真的是太慢了 QWQ</p>\n<p>pom.xml 文件中的 build 标签下配置 tomcat 插件:</p>\n<figure class=\"highlight xml\"><figcaption data-lang=\"XML\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>build</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>finalName</span><span class=\"token punctuation\">></span></span>SSM_demo<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>finalName</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>plugins</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>plugin</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>org.apache.tomcat.maven<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>tomcat7-maven-plugin<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>2.2<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>configuration</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>port</span><span class=\"token punctuation\">></span></span>80<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>port</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>path</span><span class=\"token punctuation\">></span></span>/<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>path</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>configuration</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>plugin</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>plugins</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>build</span><span class=\"token punctuation\">></span></span></pre></td></tr></table></figure><p>80 端口为启动端口,你也可以进行修改,例如修改到 8090</p>\n<figure class=\"highlight xml\"><figcaption data-lang=\"XML\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>port</span><span class=\"token punctuation\">></span></span>8090<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>port</span><span class=\"token punctuation\">></span></span></pre></td></tr></table></figure><p><strong>第三步:Java 版本配置</strong></p>\n<p>其实这是一个<strong>坑点</strong>我们需要在 pom 文件加上这两行:</p>\n<figure class=\"highlight xml\"><figcaption data-lang=\"XML\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>properties</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>maven.compiler.source</span><span class=\"token punctuation\">></span></span>8<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>maven.compiler.source</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>maven.compiler.target</span><span class=\"token punctuation\">></span></span>8<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>maven.compiler.target</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>properties</span><span class=\"token punctuation\">></span></span></pre></td></tr></table></figure><p>这是在声明我们的 Java 版本为 java8,这个一定要根据我们项目的 java 版本来填写</p>\n<h3 id=\"最终展示\"><a class=\"markdownIt-Anchor\" href=\"#最终展示\">#</a> 最终展示</h3>\n<figure class=\"highlight xml\"><figcaption data-lang=\"XML\"><span>pom.xml</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>project</span> <span class=\"token attr-name\">xmlns</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>http://maven.apache.org/POM/4.0.0<span class=\"token punctuation\">\"</span></span> </pre></td></tr><tr><td data-num=\"2\"></td><td><pre> <span class=\"token attr-name\"><span class=\"token namespace\">xmlns:</span>xsi</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>http://www.w3.org/2001/XMLSchema-instance<span class=\"token punctuation\">\"</span></span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> <span class=\"token attr-name\"><span class=\"token namespace\">xsi:</span>schemaLocation</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>http://maven.apache.org/POM/4.0.0 </pre></td></tr><tr><td data-num=\"4\"></td><td><pre> http://maven.apache.org/maven-v4_0_0.xsd<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>modelVersion</span><span class=\"token punctuation\">></span></span>4.0.0<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>modelVersion</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>com.KarryCode<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>SSM_demo<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>packaging</span><span class=\"token punctuation\">></span></span>war<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>packaging</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>properties</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>maven.compiler.source</span><span class=\"token punctuation\">></span></span>8<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>maven.compiler.source</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>maven.compiler.target</span><span class=\"token punctuation\">></span></span>8<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>maven.compiler.target</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>properties</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>1.0-SNAPSHOT<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>name</span><span class=\"token punctuation\">></span></span>SSM_demo Maven Webapp<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>name</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>url</span><span class=\"token punctuation\">></span></span>http://maven.apache.org<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>url</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependencies</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>junit<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>junit<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>4.13.2<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>scope</span><span class=\"token punctuation\">></span></span>test<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>scope</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>org.springframework<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>spring-webmvc<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>5.2.10.RELEASE<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>org.mybatis<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>mybatis<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>3.5.9<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>org.mybatis<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>mybatis-spring<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>2.0.7<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>org.springframework<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"40\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>spring-jdbc<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"41\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>5.0.2.RELEASE<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"42\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"43\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"44\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>mysql<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"45\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>mysql-connector-java<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"46\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>8.0.31<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"47\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"48\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"49\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>com.alibaba<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"50\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>druid<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"51\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>1.2.16<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"52\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"53\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"54\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>javax.servlet<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"55\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>servlet-api<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"56\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>2.5<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"57\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>scope</span><span class=\"token punctuation\">></span></span>provided<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>scope</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"58\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"59\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"60\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>com.fasterxml.jackson.core<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"61\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>jackson-databind<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"62\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>2.13.4<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"63\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependency</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"64\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>dependencies</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"65\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>build</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"66\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>finalName</span><span class=\"token punctuation\">></span></span>SSM_demo<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>finalName</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"67\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>plugins</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"68\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>plugin</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"69\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>groupId</span><span class=\"token punctuation\">></span></span>org.apache.tomcat.maven<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>groupId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"70\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>artifactId</span><span class=\"token punctuation\">></span></span>tomcat7-maven-plugin<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>artifactId</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"71\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>version</span><span class=\"token punctuation\">></span></span>2.2<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>version</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"72\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>configuration</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"73\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>port</span><span class=\"token punctuation\">></span></span>80<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>port</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"74\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>path</span><span class=\"token punctuation\">></span></span>/<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>path</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"75\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>configuration</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"76\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>plugin</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"77\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>plugins</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"78\"></td><td><pre> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>build</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"79\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>project</span><span class=\"token punctuation\">></span></span></pre></td></tr></table></figure><h2 id=\"创建jdbcproperties文件\"><a class=\"markdownIt-Anchor\" href=\"#创建jdbcproperties文件\">#</a> 创建 JDBC.properties 文件</h2>\n<p>在 <code>resource</code> 目录下创建<strong> jdbc.properties</strong></p>\n<figure class=\"highlight properties\"><figcaption data-lang=\".properties\"><span>JdbcProperties</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token key attr-name\">jdbc.driver</span> <span class=\"token punctuation\">=</span> <span class=\"token value attr-value\">com.mysql.cj.jdbc.Driver</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token key attr-name\">jdbc.url</span> <span class=\"token value attr-value\">= </span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token key attr-name\">jdbc.username</span> <span class=\"token value attr-value\">= </span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token key attr-name\">jdbc.password</span> <span class=\"token value attr-value\">=</span></pre></td></tr></table></figure><p>等号后面的根据自己的需要进行填写</p>\n<p>为了测试,我还创建的一张表:</p>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/Q1qrlnCDZFi39c8.png\" alt=\"4.png\"></p>\n<p>这是我的生成脚本:</p>\n<figure class=\"highlight sql\"><figcaption data-lang=\"SQL\"><span>生成脚本</span></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">create</span> <span class=\"token keyword\">table</span> tb_book</pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token punctuation\">(</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> id <span class=\"token keyword\">int</span> <span class=\"token keyword\">auto_increment</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token keyword\">primary</span> <span class=\"token keyword\">key</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre> <span class=\"token keyword\">type</span> <span class=\"token keyword\">varchar</span><span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span> <span class=\"token boolean\">null</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> name <span class=\"token keyword\">varchar</span><span class=\"token punctuation\">(</span><span class=\"token number\">50</span><span class=\"token punctuation\">)</span> <span class=\"token boolean\">null</span><span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> description <span class=\"token keyword\">varchar</span><span class=\"token punctuation\">(</span><span class=\"token number\">255</span><span class=\"token punctuation\">)</span> <span class=\"token boolean\">null</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr></table></figure><h2 id=\"创建mapper代理包\"><a class=\"markdownIt-Anchor\" href=\"#创建mapper代理包\">#</a> 创建 mapper 代理包</h2>\n<p>首先在 resource 目录下创建与 java 源代码目录一样的包,切记一定要以 “/” 的分割形式去创建,</p>\n<p>例如:<mark>com/KarryCode/mapper</mark></p>\n<p>创建好后,后置在这个目录下创建对应的 xml,我们稍后再说!</p>\n<h2 id=\"创建配置文件配置类\"><a class=\"markdownIt-Anchor\" href=\"#创建配置文件配置类\">#</a> 创建配置文件(配置类)</h2>\n<p>这部分将以配置类的形式进行配置。</p>\n<h3 id=\"spring_mybatis整合配置\"><a class=\"markdownIt-Anchor\" href=\"#spring_mybatis整合配置\">#</a> Spring_Mybatis 整合配置</h3>\n<p>首先在 config 包下创建<mark> Spring_Mybatis 配置类</mark></p>\n<figure class=\"highlight java\"><figcaption data-lang=\"java\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">package</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>config<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">com<span class=\"token punctuation\">.</span>alibaba<span class=\"token punctuation\">.</span>druid<span class=\"token punctuation\">.</span>pool<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">DruidDataSource</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>mybatis<span class=\"token punctuation\">.</span>spring<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">SqlSessionFactoryBean</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>mybatis<span class=\"token punctuation\">.</span>spring<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">MapperScan</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>beans<span class=\"token punctuation\">.</span>factory<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">Value</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">Bean</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">ComponentScan</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">Configuration</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">PropertySource</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>jdbc<span class=\"token punctuation\">.</span>datasource<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">DataSourceTransactionManager</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>transaction<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">PlatformTransactionManager</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>transaction<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">EnableTransactionManagement</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre></pre></td></tr><tr><td data-num=\"15\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">javax<span class=\"token punctuation\">.</span>sql<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">DataSource</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre></pre></td></tr><tr><td data-num=\"17\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"18\"></td><td><pre> * @Author KarryLiu</pre></td></tr><tr><td data-num=\"19\"></td><td><pre> * @Creed may all the beauty be blessed</pre></td></tr><tr><td data-num=\"20\"></td><td><pre> * @ClassName SpringConfig</pre></td></tr><tr><td data-num=\"21\"></td><td><pre> * @Description TODO Spring 核心配置类</pre></td></tr><tr><td data-num=\"22\"></td><td><pre> * @Version 1.0</pre></td></tr><tr><td data-num=\"23\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre><span class=\"token annotation punctuation\">@Configuration</span> <span class=\"token comment\">//TODO 核心配置唯一标识</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre><span class=\"token annotation punctuation\">@ComponentScan</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"com.KarryCode.service\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"com.KarryCode.bean\"</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">//TODO 注解扫描指定包</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre><span class=\"token annotation punctuation\">@PropertySource</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"classpath:jdbc.properties\"</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">//TODO 加载 JDBC 配置类</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre><span class=\"token annotation punctuation\">@MapperScan</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"com.KarryCode.mapper\"</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">//TODO MyBatis 基于包扫描方式识别 Mapper</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre><span class=\"token annotation punctuation\">@EnableTransactionManagement</span> <span class=\"token comment\">//TODO 事务的自动代理,注解驱动</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Spring_MybatisConfig</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token annotation punctuation\">@Bean</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token comment\">//TODO DruidDataSource 数据源的产生</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token class-name\">DataSource</span> <span class=\"token function\">dataSource</span><span class=\"token punctuation\">(</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token annotation punctuation\">@Value</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"${jdbc.driver}\"</span><span class=\"token punctuation\">)</span> <span class=\"token class-name\">String</span> driver<span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token annotation punctuation\">@Value</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"${jdbc.url}\"</span><span class=\"token punctuation\">)</span> <span class=\"token class-name\">String</span> url<span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre> <span class=\"token annotation punctuation\">@Value</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"${jdbc.username}\"</span><span class=\"token punctuation\">)</span> <span class=\"token class-name\">String</span> username<span class=\"token punctuation\">,</span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> <span class=\"token annotation punctuation\">@Value</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"${jdbc.password}\"</span><span class=\"token punctuation\">)</span> <span class=\"token class-name\">String</span> password</pre></td></tr><tr><td data-num=\"37\"></td><td><pre> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre> <span class=\"token class-name\">DruidDataSource</span> dataSource <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">DruidDataSource</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre> dataSource<span class=\"token punctuation\">.</span><span class=\"token function\">setDriverClassName</span><span class=\"token punctuation\">(</span>driver<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"40\"></td><td><pre> dataSource<span class=\"token punctuation\">.</span><span class=\"token function\">setUrl</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"41\"></td><td><pre> dataSource<span class=\"token punctuation\">.</span><span class=\"token function\">setUsername</span><span class=\"token punctuation\">(</span>username<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"42\"></td><td><pre> dataSource<span class=\"token punctuation\">.</span><span class=\"token function\">setPassword</span><span class=\"token punctuation\">(</span>password<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"43\"></td><td><pre> <span class=\"token comment\">// 里面还可以配置更多关于数据库连接池的选项.......</span></pre></td></tr><tr><td data-num=\"44\"></td><td><pre> <span class=\"token keyword\">return</span> dataSource<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"45\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"46\"></td><td><pre></pre></td></tr><tr><td data-num=\"47\"></td><td><pre> <span class=\"token annotation punctuation\">@Bean</span></pre></td></tr><tr><td data-num=\"48\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token class-name\">SqlSessionFactoryBean</span> <span class=\"token function\">sqlSessionFactoryBean</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">DataSource</span> dataSource<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"49\"></td><td><pre> <span class=\"token comment\">//TODO sqlSessionFactoryBean MybatisBeans 加载</span></pre></td></tr><tr><td data-num=\"50\"></td><td><pre> <span class=\"token class-name\">SqlSessionFactoryBean</span> sqlSessionFactoryBean <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">SqlSessionFactoryBean</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"51\"></td><td><pre> sqlSessionFactoryBean<span class=\"token punctuation\">.</span><span class=\"token function\">setDataSource</span><span class=\"token punctuation\">(</span>dataSource<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"52\"></td><td><pre> <span class=\"token keyword\">return</span> sqlSessionFactoryBean<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"53\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"54\"></td><td><pre></pre></td></tr><tr><td data-num=\"55\"></td><td><pre> <span class=\"token annotation punctuation\">@Bean</span></pre></td></tr><tr><td data-num=\"56\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token class-name\">PlatformTransactionManager</span> <span class=\"token function\">transactionManager</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">DataSource</span> dataSource<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"57\"></td><td><pre> <span class=\"token comment\">//TODO 平台事务管理</span></pre></td></tr><tr><td data-num=\"58\"></td><td><pre> <span class=\"token class-name\">DataSourceTransactionManager</span> dataSourceTransactionManager <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">DataSourceTransactionManager</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"59\"></td><td><pre> dataSourceTransactionManager<span class=\"token punctuation\">.</span><span class=\"token function\">setDataSource</span><span class=\"token punctuation\">(</span>dataSource<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"60\"></td><td><pre> <span class=\"token keyword\">return</span> dataSourceTransactionManager<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"61\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"62\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><p>具体内容不展开讲解,主要概述一下注解以及方法的作用:</p>\n<p><mark>@MapperScan</mark>:指定包扫描的路径。</p>\n<p><mark>DataSource dataSource</mark>:数据源的产生。</p>\n<p><mark>PlatformTransactionManager transactionManager</mark>:事务交由 Spring 管理。</p>\n<h3 id=\"springmvc整合配置\"><a class=\"markdownIt-Anchor\" href=\"#springmvc整合配置\">#</a> SpringMVC 整合配置</h3>\n<p>同样地,在 config 包下创建 SpringMvcConfig</p>\n<figure class=\"highlight java\"><figcaption data-lang=\"java\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">package</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>config<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">ComponentScan</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">Configuration</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>web<span class=\"token punctuation\">.</span>servlet<span class=\"token punctuation\">.</span>config<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">EnableWebMvc</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre></pre></td></tr><tr><td data-num=\"7\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"8\"></td><td><pre> * @Author KarryLiu</pre></td></tr><tr><td data-num=\"9\"></td><td><pre> * @Creed may all the beauty be blessed</pre></td></tr><tr><td data-num=\"10\"></td><td><pre> * @PackageName com.KarryCode.config</pre></td></tr><tr><td data-num=\"11\"></td><td><pre> * @ClassName SpringMvcConfig</pre></td></tr><tr><td data-num=\"12\"></td><td><pre> * @Description TODO</pre></td></tr><tr><td data-num=\"13\"></td><td><pre> * @Version 1.0</pre></td></tr><tr><td data-num=\"14\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre><span class=\"token annotation punctuation\">@Configuration</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre><span class=\"token annotation punctuation\">@EnableWebMvc</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre><span class=\"token annotation punctuation\">@ComponentScan</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"com.KarryCode.controller\"</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">SpringMvcConfig</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h3 id=\"servlet-api整合配置\"><a class=\"markdownIt-Anchor\" href=\"#servlet-api整合配置\">#</a> Servlet-api 整合配置</h3>\n<p>同样地,在 config 包下创建 ServletConfig</p>\n<figure class=\"highlight java\"><figcaption data-lang=\"java\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">package</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>config<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>web<span class=\"token punctuation\">.</span>servlet<span class=\"token punctuation\">.</span>support<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">AbstractAnnotationConfigDispatcherServletInitializer</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">ServletConfig</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">AbstractAnnotationConfigDispatcherServletInitializer</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre> <span class=\"token annotation punctuation\">@Override</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre> <span class=\"token keyword\">protected</span> <span class=\"token class-name\">Class</span><span class=\"token generics\"><span class=\"token punctuation\"><</span><span class=\"token operator\">?</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token function\">getRootConfigClasses</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Class</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">{</span><span class=\"token class-name\">Spring_MybatisConfig</span><span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre></pre></td></tr><tr><td data-num=\"11\"></td><td><pre> <span class=\"token annotation punctuation\">@Override</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token keyword\">protected</span> <span class=\"token class-name\">Class</span><span class=\"token generics\"><span class=\"token punctuation\"><</span><span class=\"token operator\">?</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token function\">getServletConfigClasses</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Class</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">{</span><span class=\"token class-name\">SpringMvcConfig</span><span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre></pre></td></tr><tr><td data-num=\"16\"></td><td><pre> <span class=\"token annotation punctuation\">@Override</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token keyword\">protected</span> <span class=\"token class-name\">String</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token function\">getServletMappings</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">String</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">{</span><span class=\"token string\">\"/\"</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><p>此时的目录结构是这样的:</p>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/lUtQbGwr6AmTeLY.png\" alt=\"5.png\"></p>\n<p><mark>至此,整合已经基本完成!</mark></p>\n<h2 id=\"bean实体类创建\"><a class=\"markdownIt-Anchor\" href=\"#bean实体类创建\">#</a> Bean 实体类创建</h2>\n<p>根据数据库里的以及逻辑关系创建 Bean 实体,在这里我先创建一个 Book 实体</p>\n<figure class=\"highlight java\"><figcaption data-lang=\"java\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">package</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>bean<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"4\"></td><td><pre> * @Author KarryLiu</pre></td></tr><tr><td data-num=\"5\"></td><td><pre> * @Creed may all the beauty be blessed</pre></td></tr><tr><td data-num=\"6\"></td><td><pre> * @PackageName com.KarryCode.bean</pre></td></tr><tr><td data-num=\"7\"></td><td><pre> * @ClassName Book</pre></td></tr><tr><td data-num=\"8\"></td><td><pre> * @Description TODO</pre></td></tr><tr><td data-num=\"9\"></td><td><pre> * @Version 1.0</pre></td></tr><tr><td data-num=\"10\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"11\"></td><td><pre><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Book</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"12\"></td><td><pre> <span class=\"token keyword\">private</span> <span class=\"token class-name\">Integer</span> id<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"13\"></td><td><pre> <span class=\"token keyword\">private</span> <span class=\"token class-name\">String</span> type<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"14\"></td><td><pre> <span class=\"token keyword\">private</span> <span class=\"token class-name\">String</span> name<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre> <span class=\"token keyword\">private</span> <span class=\"token class-name\">String</span> description<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token comment\">// 省略 getter/setter/ 构造器(有参 / 无参)/toString</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"mapper接口创建\"><a class=\"markdownIt-Anchor\" href=\"#mapper接口创建\">#</a> mapper 接口创建</h2>\n<p>在 mapper 包下创建一个 mapper 接口 BookMapper</p>\n<figure class=\"highlight java\"><figcaption data-lang=\"java\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">package</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>mapper<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>bean<span class=\"token punctuation\">.</span>Book<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>apache<span class=\"token punctuation\">.</span>ibatis<span class=\"token punctuation\">.</span>annotations<span class=\"token punctuation\">.</span></span><span class=\"token operator\">*</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">java<span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">List</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"9\"></td><td><pre> * @Author KarryLiu</pre></td></tr><tr><td data-num=\"10\"></td><td><pre> * @Creed may all the beauty be blessed</pre></td></tr><tr><td data-num=\"11\"></td><td><pre> * @PackageName com.KarryCode.mapper</pre></td></tr><tr><td data-num=\"12\"></td><td><pre> * @ClassName BookMapper</pre></td></tr><tr><td data-num=\"13\"></td><td><pre> * @Description TODO</pre></td></tr><tr><td data-num=\"14\"></td><td><pre> * @Version 1.0</pre></td></tr><tr><td data-num=\"15\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre><span class=\"token keyword\">public</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">BookMapper</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token annotation punctuation\">@Insert</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"insert into ssm_db.tb_book values (null,#{type},#{name},#{description})\"</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token keyword\">int</span> <span class=\"token function\">save</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Book</span> book<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token annotation punctuation\">@Update</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"update ssm_db.tb_book set type=#{type},name=#{name},description=#{description} where id=#{id}\"</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token keyword\">int</span> <span class=\"token function\">update</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Book</span> book<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token annotation punctuation\">@Delete</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"delete from ssm_db.tb_book where tb_book.id=#{id}\"</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token keyword\">int</span> <span class=\"token function\">delete</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Integer</span> id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token annotation punctuation\">@Select</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"select * from ssm_db.tb_book where id=#{id}\"</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token annotation punctuation\">@ResultType</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Book</span><span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token class-name\">Book</span> <span class=\"token function\">getBookById</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Integer</span> id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token annotation punctuation\">@Select</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"select * from ssm_db.tb_book\"</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token class-name\">List</span><span class=\"token generics\"><span class=\"token punctuation\"><</span><span class=\"token class-name\">Book</span><span class=\"token punctuation\">></span></span> <span class=\"token function\">getBookList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><p>通过注解方式配置了增删改查四种方法</p>\n<h2 id=\"mapper代理xml创建\"><a class=\"markdownIt-Anchor\" href=\"#mapper代理xml创建\">#</a> mapper 代理 xml 创建</h2>\n<p>虽然没啥用,但是创建了也没什么坏处,在 resource 的对应目录下创建 BookMapper.xml</p>\n<figure class=\"highlight xml\"><figcaption data-lang=\"XML\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token prolog\"><?xml version=\"1.0\" encoding=\"UTF-8\" ?></span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token doctype\"><span class=\"token punctuation\"><!</span><span class=\"token doctype-tag\">DOCTYPE</span> <span class=\"token name\">mapper</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre> <span class=\"token name\">PUBLIC</span> <span class=\"token string\">\"-//mybatis.org//DTD Mapper 3.0//EN\"</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre> <span class=\"token string\">\"https://mybatis.org/dtd/mybatis-3-mapper.dtd\"</span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"><</span>mapper</span> <span class=\"token attr-name\">namespace</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>com.KarryCode.mapper.BookMapper<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre></pre></td></tr><tr><td data-num=\"7\"></td><td><pre><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\"></</span>mapper</span><span class=\"token punctuation\">></span></span></pre></td></tr></table></figure><h2 id=\"service逻辑创建\"><a class=\"markdownIt-Anchor\" href=\"#service逻辑创建\">#</a> Service 逻辑创建</h2>\n<p><mark>BookService 接口</mark></p>\n<figure class=\"highlight java\"><figcaption data-lang=\"java\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">package</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>service<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>bean<span class=\"token punctuation\">.</span>Book<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>transaction<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">Transactional</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">java<span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">List</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"9\"></td><td><pre> * @Author KarryLiu</pre></td></tr><tr><td data-num=\"10\"></td><td><pre> * @Creed may all the beauty be blessed</pre></td></tr><tr><td data-num=\"11\"></td><td><pre> * @ClassName BookService</pre></td></tr><tr><td data-num=\"12\"></td><td><pre> * @Description TODO</pre></td></tr><tr><td data-num=\"13\"></td><td><pre> * @Version 1.0</pre></td></tr><tr><td data-num=\"14\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"15\"></td><td><pre><span class=\"token annotation punctuation\">@Transactional</span></pre></td></tr><tr><td data-num=\"16\"></td><td><pre><span class=\"token keyword\">public</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">BookService</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre> <span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"18\"></td><td><pre> * @param book</pre></td></tr><tr><td data-num=\"19\"></td><td><pre> * @return boolean</pre></td></tr><tr><td data-num=\"20\"></td><td><pre> * @Author KarryLiu_刘珂瑞</pre></td></tr><tr><td data-num=\"21\"></td><td><pre> * @Date 2023/8/14 下午 10:58</pre></td></tr><tr><td data-num=\"22\"></td><td><pre> * @Description TODO 保存</pre></td></tr><tr><td data-num=\"23\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token keyword\">boolean</span> <span class=\"token function\">save</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Book</span> book<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"26\"></td><td><pre> * @param book</pre></td></tr><tr><td data-num=\"27\"></td><td><pre> * @return boolean</pre></td></tr><tr><td data-num=\"28\"></td><td><pre> * @Author KarryLiu_刘珂瑞</pre></td></tr><tr><td data-num=\"29\"></td><td><pre> * @Date 2023/8/14 下午 10:58</pre></td></tr><tr><td data-num=\"30\"></td><td><pre> * @Description TODO 修改</pre></td></tr><tr><td data-num=\"31\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token keyword\">boolean</span> <span class=\"token function\">update</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Book</span> book<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"34\"></td><td><pre> * @param id</pre></td></tr><tr><td data-num=\"35\"></td><td><pre> * @return boolean</pre></td></tr><tr><td data-num=\"36\"></td><td><pre> * @Author KarryLiu_刘珂瑞</pre></td></tr><tr><td data-num=\"37\"></td><td><pre> * @Date 2023/8/14 下午 10:58</pre></td></tr><tr><td data-num=\"38\"></td><td><pre> * @Description TODO 根据 id 删除</pre></td></tr><tr><td data-num=\"39\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"40\"></td><td><pre> <span class=\"token keyword\">boolean</span> <span class=\"token function\">delete</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Integer</span> id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"41\"></td><td><pre> <span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"42\"></td><td><pre> * @param id</pre></td></tr><tr><td data-num=\"43\"></td><td><pre> * @return edu.beihua.bean.Book</pre></td></tr><tr><td data-num=\"44\"></td><td><pre> * @Author KarryLiu_刘珂瑞</pre></td></tr><tr><td data-num=\"45\"></td><td><pre> * @Date 2023/8/14 下午 10:59</pre></td></tr><tr><td data-num=\"46\"></td><td><pre> * @Description TODO 根据 id 查询</pre></td></tr><tr><td data-num=\"47\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"48\"></td><td><pre> <span class=\"token class-name\">Book</span> <span class=\"token function\">getBookById</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Integer</span> id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"49\"></td><td><pre> <span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"50\"></td><td><pre> * @param</pre></td></tr><tr><td data-num=\"51\"></td><td><pre> * @return java.util.List<edu.beihua.bean.Book></pre></td></tr><tr><td data-num=\"52\"></td><td><pre> * @Author KarryLiu_刘珂瑞</pre></td></tr><tr><td data-num=\"53\"></td><td><pre> * @Date 2023/8/14 下午 10:59</pre></td></tr><tr><td data-num=\"54\"></td><td><pre> * @Description TODO 查询全部</pre></td></tr><tr><td data-num=\"55\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"56\"></td><td><pre> <span class=\"token class-name\">List</span><span class=\"token generics\"><span class=\"token punctuation\"><</span><span class=\"token class-name\">Book</span><span class=\"token punctuation\">></span></span> <span class=\"token function\">getBookList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"57\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><p><mark>BookService 接口实现</mark></p>\n<figure class=\"highlight java\"><figcaption data-lang=\"java\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">package</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>service<span class=\"token punctuation\">.</span>impl<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>bean<span class=\"token punctuation\">.</span>Book<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>mapper<span class=\"token punctuation\">.</span>BookMapper<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>service<span class=\"token punctuation\">.</span>BookService<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>stereotype<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">Service</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">javax<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">Resource</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">java<span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">List</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre></pre></td></tr><tr><td data-num=\"11\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"12\"></td><td><pre> * @Author KarryLiu</pre></td></tr><tr><td data-num=\"13\"></td><td><pre> * @Creed may all the beauty be blessed</pre></td></tr><tr><td data-num=\"14\"></td><td><pre> * @Date 2023/8/14 下午 10:43</pre></td></tr><tr><td data-num=\"15\"></td><td><pre> * @ClassName BookServiceImpl</pre></td></tr><tr><td data-num=\"16\"></td><td><pre> * @Description TODO</pre></td></tr><tr><td data-num=\"17\"></td><td><pre> * @Version 1.0</pre></td></tr><tr><td data-num=\"18\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre><span class=\"token annotation punctuation\">@Service</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">BookServiceImpl</span> <span class=\"token keyword\">implements</span> <span class=\"token class-name\">BookService</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token annotation punctuation\">@Resource</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token keyword\">private</span> <span class=\"token class-name\">BookMapper</span> bookMapper<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token annotation punctuation\">@Override</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token keyword\">boolean</span> <span class=\"token function\">save</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Book</span> book<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token class-name\">System</span><span class=\"token punctuation\">.</span>out<span class=\"token punctuation\">.</span><span class=\"token function\">println</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"save=====>Service\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token keyword\">int</span> save <span class=\"token operator\">=</span> bookMapper<span class=\"token punctuation\">.</span><span class=\"token function\">save</span><span class=\"token punctuation\">(</span>book<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>save<span class=\"token operator\">></span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token punctuation\">}</span><span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> <span class=\"token annotation punctuation\">@Override</span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token keyword\">boolean</span> <span class=\"token function\">update</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Book</span> book<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre> <span class=\"token class-name\">System</span><span class=\"token punctuation\">.</span>out<span class=\"token punctuation\">.</span><span class=\"token function\">println</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"update=====>Service\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre></pre></td></tr><tr><td data-num=\"40\"></td><td><pre> bookMapper<span class=\"token punctuation\">.</span><span class=\"token function\">update</span><span class=\"token punctuation\">(</span>book<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"41\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"42\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"43\"></td><td><pre></pre></td></tr><tr><td data-num=\"44\"></td><td><pre> <span class=\"token annotation punctuation\">@Override</span></pre></td></tr><tr><td data-num=\"45\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token keyword\">boolean</span> <span class=\"token function\">delete</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Integer</span> id<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"46\"></td><td><pre> <span class=\"token class-name\">System</span><span class=\"token punctuation\">.</span>out<span class=\"token punctuation\">.</span><span class=\"token function\">println</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"delete=====>Service\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"47\"></td><td><pre></pre></td></tr><tr><td data-num=\"48\"></td><td><pre> bookMapper<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"49\"></td><td><pre> <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"50\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"51\"></td><td><pre></pre></td></tr><tr><td data-num=\"52\"></td><td><pre> <span class=\"token annotation punctuation\">@Override</span></pre></td></tr><tr><td data-num=\"53\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token class-name\">Book</span> <span class=\"token function\">getBookById</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Integer</span> id<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"54\"></td><td><pre> <span class=\"token class-name\">System</span><span class=\"token punctuation\">.</span>out<span class=\"token punctuation\">.</span><span class=\"token function\">println</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"getBookById=====>Service\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"55\"></td><td><pre></pre></td></tr><tr><td data-num=\"56\"></td><td><pre> <span class=\"token class-name\">Book</span> book <span class=\"token operator\">=</span> bookMapper<span class=\"token punctuation\">.</span><span class=\"token function\">getBookById</span><span class=\"token punctuation\">(</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"57\"></td><td><pre> <span class=\"token keyword\">return</span> book<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"58\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"59\"></td><td><pre></pre></td></tr><tr><td data-num=\"60\"></td><td><pre> <span class=\"token annotation punctuation\">@Override</span></pre></td></tr><tr><td data-num=\"61\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token class-name\">List</span><span class=\"token generics\"><span class=\"token punctuation\"><</span><span class=\"token class-name\">Book</span><span class=\"token punctuation\">></span></span> <span class=\"token function\">getBookList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"62\"></td><td><pre> <span class=\"token class-name\">System</span><span class=\"token punctuation\">.</span>out<span class=\"token punctuation\">.</span><span class=\"token function\">println</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"getBookList=====>Service\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"63\"></td><td><pre> <span class=\"token keyword\">return</span> bookMapper<span class=\"token punctuation\">.</span><span class=\"token function\">getBookList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"64\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"65\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><h2 id=\"springmybatis通路检测\"><a class=\"markdownIt-Anchor\" href=\"#springmybatis通路检测\">#</a> Spring—Mybatis 通路检测</h2>\n<p>编写测试类,观察输出</p>\n<figure class=\"highlight java\"><figcaption data-lang=\"java\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>bean<span class=\"token punctuation\">.</span>Book<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>config<span class=\"token punctuation\">.</span>Spring_MybatisConfig<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>service<span class=\"token punctuation\">.</span>BookService<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>junit<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">Test</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">AnnotationConfigApplicationContext</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre></pre></td></tr><tr><td data-num=\"7\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">java<span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">List</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"8\"></td><td><pre></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"10\"></td><td><pre> * @Author KarryLiu</pre></td></tr><tr><td data-num=\"11\"></td><td><pre> * @Creed may all the beauty be blessed</pre></td></tr><tr><td data-num=\"12\"></td><td><pre> * @PackageName PACKAGE_NAME</pre></td></tr><tr><td data-num=\"13\"></td><td><pre> * @ClassName mybatisTest</pre></td></tr><tr><td data-num=\"14\"></td><td><pre> * @Description TODO</pre></td></tr><tr><td data-num=\"15\"></td><td><pre> * @Version 1.0</pre></td></tr><tr><td data-num=\"16\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"17\"></td><td><pre><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> mybatisSpringTest <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"18\"></td><td><pre> <span class=\"token annotation punctuation\">@Test</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">testMybatisSpring</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre> <span class=\"token class-name\">AnnotationConfigApplicationContext</span> annotationConfigApplicationContext <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">AnnotationConfigApplicationContext</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Spring_MybatisConfig</span><span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre> <span class=\"token class-name\">BookService</span> bookService <span class=\"token operator\">=</span> annotationConfigApplicationContext<span class=\"token punctuation\">.</span><span class=\"token function\">getBean</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">BookService</span><span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre> <span class=\"token class-name\">List</span><span class=\"token generics\"><span class=\"token punctuation\"><</span><span class=\"token class-name\">Book</span><span class=\"token punctuation\">></span></span> bookList <span class=\"token operator\">=</span> bookService<span class=\"token punctuation\">.</span><span class=\"token function\">getBookList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token class-name\">System</span><span class=\"token punctuation\">.</span>out<span class=\"token punctuation\">.</span><span class=\"token function\">println</span><span class=\"token punctuation\">(</span>bookList<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><details class=\"info\"><summary>输出</summary><div>\n<div class=\"tab\" data-id=\"id1\" data-title=\"\">\n<p>信息: {dataSource-1} inited<br>\ngetBookList=====>Service<br>\n [Book {id=1, type=‘计算机’, name=‘软件工程’, description=‘吼吼吼吼’}, Book {id=2, type=‘文学’, name=‘儒家经典’, description=‘儒家好书啊!!!!!’}, Book {id=3, type=‘科技’, name=‘百科全书’, description=‘真不错!!!!’}, Book {id=4, type=‘美术’, name=‘当代顶流美术’, description=‘好书啊好书!!!!’}, Book {id=6, type=‘科技’, name=‘百科全书’, description=‘真不错!!!!’}, Book {id=7, type=‘科技’, name=‘百科全书’, description=‘真不错!!!!’}]</p>\n<p>进程已结束,退出代码 0</p>\n</div>\n</div></details>\n<p><mark>至此,Spring—Mbatis 整合完成</mark></p>\n<h2 id=\"构建controller\"><a class=\"markdownIt-Anchor\" href=\"#构建controller\">#</a> 构建 Controller</h2>\n<p>在 controller 包下创建 BookController</p>\n<figure class=\"highlight java\"><figcaption data-lang=\"java\"></figcaption><table><tr><td data-num=\"1\"></td><td><pre><span class=\"token keyword\">package</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>controller<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"2\"></td><td><pre></pre></td></tr><tr><td data-num=\"3\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>bean<span class=\"token punctuation\">.</span>Book<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"4\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token namespace\">com<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">KarryCode</span><span class=\"token punctuation\">.</span>service<span class=\"token punctuation\">.</span>BookService<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"5\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>transaction<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">Transactional</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"6\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.</span>springframework<span class=\"token punctuation\">.</span>web<span class=\"token punctuation\">.</span>bind<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token operator\">*</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"7\"></td><td><pre></pre></td></tr><tr><td data-num=\"8\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">javax<span class=\"token punctuation\">.</span>annotation<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">Resource</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"9\"></td><td><pre><span class=\"token keyword\">import</span> <span class=\"token import\"><span class=\"token namespace\">java<span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span></span><span class=\"token class-name\">List</span></span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"10\"></td><td><pre></pre></td></tr><tr><td data-num=\"11\"></td><td><pre><span class=\"token comment\">/**</pre></td></tr><tr><td data-num=\"12\"></td><td><pre> * @Author KarryLiu</pre></td></tr><tr><td data-num=\"13\"></td><td><pre> * @Creed may all the beauty be blessed</pre></td></tr><tr><td data-num=\"14\"></td><td><pre> * @PackageName com.KarryCode.controller</pre></td></tr><tr><td data-num=\"15\"></td><td><pre> * @ClassName BookController</pre></td></tr><tr><td data-num=\"16\"></td><td><pre> * @Description TODO</pre></td></tr><tr><td data-num=\"17\"></td><td><pre> * @Version 1.0</pre></td></tr><tr><td data-num=\"18\"></td><td><pre> */</span></pre></td></tr><tr><td data-num=\"19\"></td><td><pre><span class=\"token annotation punctuation\">@RestController</span></pre></td></tr><tr><td data-num=\"20\"></td><td><pre><span class=\"token annotation punctuation\">@Transactional</span></pre></td></tr><tr><td data-num=\"21\"></td><td><pre><span class=\"token annotation punctuation\">@RequestMapping</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"/books\"</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"22\"></td><td><pre><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">BookController</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"23\"></td><td><pre> <span class=\"token annotation punctuation\">@Resource</span></pre></td></tr><tr><td data-num=\"24\"></td><td><pre> <span class=\"token keyword\">private</span> <span class=\"token class-name\">BookService</span> bookService<span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"25\"></td><td><pre> <span class=\"token annotation punctuation\">@PostMapping</span></pre></td></tr><tr><td data-num=\"26\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token keyword\">boolean</span> <span class=\"token function\">save</span><span class=\"token punctuation\">(</span><span class=\"token annotation punctuation\">@RequestBody</span> <span class=\"token class-name\">Book</span> book<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"27\"></td><td><pre> <span class=\"token keyword\">return</span> bookService<span class=\"token punctuation\">.</span><span class=\"token function\">save</span><span class=\"token punctuation\">(</span>book<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"28\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"29\"></td><td><pre> <span class=\"token annotation punctuation\">@PutMapping</span></pre></td></tr><tr><td data-num=\"30\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token keyword\">boolean</span> <span class=\"token function\">update</span><span class=\"token punctuation\">(</span><span class=\"token annotation punctuation\">@RequestBody</span> <span class=\"token class-name\">Book</span> book<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"31\"></td><td><pre> <span class=\"token keyword\">return</span> bookService<span class=\"token punctuation\">.</span><span class=\"token function\">update</span><span class=\"token punctuation\">(</span>book<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"32\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"33\"></td><td><pre> <span class=\"token annotation punctuation\">@DeleteMapping</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"/{id}\"</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"34\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token keyword\">boolean</span> <span class=\"token function\">delete</span><span class=\"token punctuation\">(</span><span class=\"token annotation punctuation\">@PathVariable</span> <span class=\"token class-name\">Integer</span> id<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"35\"></td><td><pre> <span class=\"token keyword\">return</span> bookService<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"36\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"37\"></td><td><pre> <span class=\"token annotation punctuation\">@GetMapping</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"/{id}\"</span><span class=\"token punctuation\">)</span></pre></td></tr><tr><td data-num=\"38\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token class-name\">Book</span> <span class=\"token function\">getBookById</span><span class=\"token punctuation\">(</span><span class=\"token annotation punctuation\">@PathVariable</span> <span class=\"token class-name\">Integer</span> id<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"39\"></td><td><pre> <span class=\"token keyword\">return</span> bookService<span class=\"token punctuation\">.</span><span class=\"token function\">getBookById</span><span class=\"token punctuation\">(</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"40\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"41\"></td><td><pre> <span class=\"token annotation punctuation\">@GetMapping</span></pre></td></tr><tr><td data-num=\"42\"></td><td><pre> <span class=\"token keyword\">public</span> <span class=\"token class-name\">List</span><span class=\"token generics\"><span class=\"token punctuation\"><</span><span class=\"token class-name\">Book</span><span class=\"token punctuation\">></span></span> <span class=\"token function\">getBookList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></pre></td></tr><tr><td data-num=\"43\"></td><td><pre> <span class=\"token keyword\">return</span> bookService<span class=\"token punctuation\">.</span><span class=\"token function\">getBookList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></pre></td></tr><tr><td data-num=\"44\"></td><td><pre> <span class=\"token punctuation\">}</span></pre></td></tr><tr><td data-num=\"45\"></td><td><pre><span class=\"token punctuation\">}</span></pre></td></tr></table></figure><p>符合 Restful 设计建议。</p>\n<h2 id=\"启动tomcat\"><a class=\"markdownIt-Anchor\" href=\"#启动tomcat\">#</a> 启动 Tomcat</h2>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/LwPvIdjzuOrF3qA.png\" alt=\"6.png\"></p>\n<h2 id=\"postman接口测试\"><a class=\"markdownIt-Anchor\" href=\"#postman接口测试\">#</a> Postman 接口测试</h2>\n<h3 id=\"存书测试\"><a class=\"markdownIt-Anchor\" href=\"#存书测试\">#</a> 存书测试</h3>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/3WONSCfKBlwZYQU.png\" alt=\"7.png\"></p>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/cWS38NF52uvHlzR.png\" alt=\"8.png\"></p>\n<p><span class=\"label success\">success</span></p>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/bW6ftFnpC4zrTGM.png\" alt=\"9.png\"></p>\n<h3 id=\"查书测试\"><a class=\"markdownIt-Anchor\" href=\"#查书测试\">#</a> 查书测试</h3>\n<h4 id=\"查询全部\"><a class=\"markdownIt-Anchor\" href=\"#查询全部\">#</a> 查询全部</h4>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/R4KpPlMejHQ1q5i.png\" alt=\"10.png\"></p>\n<h4 id=\"指定id查书\"><a class=\"markdownIt-Anchor\" href=\"#指定id查书\">#</a> 指定 id 查书</h4>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/u2EnQV3ctBeG9PT.png\" alt=\"11.png\"></p>\n<h3 id=\"更新书\"><a class=\"markdownIt-Anchor\" href=\"#更新书\">#</a> 更新书</h3>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/Fp3PiJ6UKnAY4sT.png\" alt=\"12.png\"></p>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/u2LeioHRw4mUtTM.png\" alt=\"13.png\"></p>\n<h3 id=\"删除测试\"><a class=\"markdownIt-Anchor\" href=\"#删除测试\">#</a> 删除测试</h3>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/8LGMQbpAStu7OCB.png\" alt=\"14.png\"></p>\n<p><img data-src=\"https://s2.loli.net/2023/08/27/68mTx7N2kGWr9PX.png\" alt=\"15.png\"></p>\n<p><mark>所有接口测试调通,至此 SSM 整合完毕</mark></p>\n<h1 id=\"总结\"><a class=\"markdownIt-Anchor\" href=\"#总结\">#</a> 总结</h1>\n<p>其实 SSM 整合还是比较简单的,通过三个框架的配置就可以完成了,后面的工作都是在进行业务创建。</p>\n<p>好了!本篇文章到这里就结束了,有什么不理解的地方或者有疑问的地方请在评论区留言,或者添加我的联系方式,欢迎各位大佬积极批评讨论!谢谢!</p>\n",
"tags": [
"开发经验",
"SSM"
]
},
{
"id": "https://735690757.github.io/Principles-of-computer-composition/Connection_between_CPU_and_memory/",
"url": "https://735690757.github.io/Principles-of-computer-composition/Connection_between_CPU_and_memory/",
"title": "CPU与存储器的连接",
"date_published": "2023-06-06T03:11:00.000Z",
"content_html": "<h1 id=\"前言\"><a class=\"markdownIt-Anchor\" href=\"#前言\">#</a> 前言</h1>\n<p>针对这一部分内容我还是推荐大家去看看书本上和其他教学视频里的内容,本篇文章只针对计算机组成原理(第 3 版)P91 页之后的内容进行简单整理汇总。</p>\n<p>接下来我将会按照书上的顺序进行叙述。</p>\n<h1 id=\"cpu-与存储器的连接\"><a class=\"markdownIt-Anchor\" href=\"#cpu-与存储器的连接\">#</a> CPU 与存储器的连接</h1>\n<h2 id=\"存储器容量扩展\"><a class=\"markdownIt-Anchor\" href=\"#存储器容量扩展\">#</a> 存储器容量扩展</h2>\n<h3 id=\"字扩展\"><a class=\"markdownIt-Anchor\" href=\"#字扩展\">#</a> 字扩展</h3>\n<p>在某些情况下,字扩展可以被视为一种扩容操作。字扩展通常指的是将一个字符或字符串转换为具有更多位数或更高精度的数据类型,以便进行更复杂的计算或存储更大的值。这个过程可能涉及到内存分配和重新分配,因此可以看作是一种扩容操作。但是,在其他情况下,字扩展可能只是简单地将一个字符或字符串进行格式化或解码,而不涉及任何内存操作。因此,是否将字扩展视为扩容取决于具体的上下文和实现方式。</p>\n<p><strong>但是我们可以简单地把字扩展理解为扩容。</strong></p>\n<p>比如,<strong>两片 1K*8 位</strong>通过字扩展扩容位逻辑上的<strong>一片 2K*8 位</strong></p>\n<h3 id=\"位扩展\"><a class=\"markdownIt-Anchor\" href=\"#位扩展\">#</a> 位扩展</h3>\n<p>位扩展是一种将一个二进制数值的位数增加的操作。在位扩展中,如果原始二进制数值的最高位为 0,则在其左侧添加 0 以增加位数;如果最高位为 1,则在其左侧添加 1 以保持符号不变。例如,将 8 位二进制数值 "00110110" 进行位扩展为 16 位,则结果为 "00000000 00110110"。位扩展通常用于将低精度数据类型转换为高精度数据类型,或者在进行算术运算时对操作数进行对齐。</p>\n<p><strong>咳咳咳,简单理解就是二进制加长</strong></p>\n<h3 id=\"字位扩展\"><a class=\"markdownIt-Anchor\" href=\"#字位扩展\">#</a> 字位扩展</h3>\n<p>字位扩展是一种将一个数据类型的位数增加的操作,其中 “字” 指的是计算机中的一个固定大小的数据单元。在字位扩展中,如果原始数据类型的最高位为 0,则在其左侧添加 0 以增加位数;如果最高位为 1,则在其左侧添加 1 以保持符号不变。例如,将 16 位有符号整数进行字位扩展为 32 位,则结果为在最高位之前添加 16 个相同的符号位。字位扩展通常用于将低精度数据类型转换为高精度数据类型,或者在进行算术运算时对操作数进行对齐。</p>\n<p><strong>简单理解就是… 结合版</strong></p>\n<h1 id=\"例题\"><a class=\"markdownIt-Anchor\" href=\"#例题\">#</a> 例题</h1>\n<p>怎么出题呢?一般都像这样:</p>\n<p>CPU 有 16 根地址线、8 根数据线,并用 MREQ 非作为访存控制信号(低电频有效),用 WR 作为读 / 写控制信号。现在有如下存储芯片:<strong>1K X 4 位 RAM、4K X 8 位 RAM、8K X 8 位 RAM、2K X 8 位 ROM、4K X 8 位 ROM、8K X 8 位 ROM</strong> 及 74138 译码器和各种门电路。现要求如下:</p>\n<ul>\n<li>主存地址空间分配:\n<ul>\n<li>6000H ~ 67FFH 为系统程序区</li>\n<li>6800H ~ 6BFFH 为用户程序区</li>\n</ul>\n</li>\n<li>合理选用上述存储芯片,说明各选几片</li>\n<li>详细画出芯片片选逻辑图</li>\n</ul>\n<h2 id=\"解\"><a class=\"markdownIt-Anchor\" href=\"#解\">#</a> 解!!</h2>\n<p><strong>第一步:写出地址空间分配范围二进制码</strong></p>\n<p>6000H ~ 67FFH 为系统程序区</p>\n<p>6800H ~ 6BFFH 为用户程序区</p>\n<p>6000H、67FFH、6800H、6BFFH 化为二进制:</p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">A15</th>\n<th>A14</th>\n<th>A13</th>\n<th style=\"text-align:center\">A12</th>\n<th>A11</th>\n<th>A10</th>\n<th>A9</th>\n<th>A8</th>\n<th>A7</th>\n<th>A6</th>\n<th>A5</th>\n<th>A4</th>\n<th>A3</th>\n<th>A2</th>\n<th>A1</th>\n<th>A0</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>0</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>0</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n<p>首先,先确定芯片,<strong>全零到全一就是一个芯片</strong></p>\n<p>先看 ROM,也就是系统区:</p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">A15</th>\n<th>A14</th>\n<th>A13</th>\n<th style=\"text-align:center\">A12</th>\n<th>A11</th>\n<th>A10</th>\n<th>A9</th>\n<th>A8</th>\n<th>A7</th>\n<th>A6</th>\n<th>A5</th>\n<th>A4</th>\n<th>A3</th>\n<th>A2</th>\n<th>A1</th>\n<th>A0</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>0</td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>0</td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>0</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n<p>A0 ~ A10 为一个 ROM,一共 11 位,理想是要一个规格为<strong> 2K X 8 位 ROM</strong></p>\n<p>再来看 RAM ,也就是用户区:</p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">A15</th>\n<th>A14</th>\n<th>A13</th>\n<th style=\"text-align:center\">A12</th>\n<th>A11</th>\n<th>A10</th>\n<th>A9</th>\n<th>A8</th>\n<th>A7</th>\n<th>A6</th>\n<th>A5</th>\n<th>A4</th>\n<th>A3</th>\n<th>A2</th>\n<th>A1</th>\n<th>A0</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>0</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>0</td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td><strong>0</strong></td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>0</td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n<td><strong>1</strong></td>\n</tr>\n</tbody>\n</table>\n<p>A0 ~ A9 为一个 RAM,一共 10 位,理想是要一个规格为<strong> 1K X 8 位 RAM</strong></p>\n<p>然后呢,我们需要对 ROM 和 RAM 进行读写,这就涉及到切换 ROM 和 RAM 芯片的问题,我们需要弄一个片选信号:</p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">A15</th>\n<th>A14</th>\n<th>A13</th>\n<th style=\"text-align:center\">A12</th>\n<th>A11</th>\n<th>A10</th>\n<th>A9</th>\n<th>A8</th>\n<th>A7</th>\n<th>A6</th>\n<th>A5</th>\n<th>A4</th>\n<th>A3</th>\n<th>A2</th>\n<th>A1</th>\n<th>A0</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td><strong>0</strong></td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td><strong>0</strong></td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td><strong>1</strong></td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td>1</td>\n<td style=\"text-align:center\">0</td>\n<td><strong>1</strong></td>\n<td>0</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n<p>上两行是 ROM,下两行是 RAM,可以看到 A11 及其关键的决定了到底选择哪一个芯片,是 ROM 还是 RAM。当 A11 为 0 时 ROM 被选中,当 A11 为 1 时 RAM 被选中。</p>\n<p>然而 74138 译码器需要三个数据输入端,这时候我们就需要再拉来两个垫背的 A12 与 A13。</p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">A15</th>\n<th>A14</th>\n<th>A13</th>\n<th style=\"text-align:center\">A12</th>\n<th>A11</th>\n<th>A10</th>\n<th>A9</th>\n<th>A8</th>\n<th>A7</th>\n<th>A6</th>\n<th>A5</th>\n<th>A4</th>\n<th>A3</th>\n<th>A2</th>\n<th>A1</th>\n<th>A0</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td><strong>1</strong></td>\n<td style=\"text-align:center\"><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td><strong>1</strong></td>\n<td style=\"text-align:center\"><strong>0</strong></td>\n<td><strong>0</strong></td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td><strong>1</strong></td>\n<td style=\"text-align:center\"><strong>0</strong></td>\n<td><strong>1</strong></td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n<td>0</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">0</td>\n<td>1</td>\n<td><strong>1</strong></td>\n<td style=\"text-align:center\"><strong>0</strong></td>\n<td><strong>1</strong></td>\n<td>0</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n<p><strong>A11 A12 A13</strong> 一次排列连接至 74138 的数据输入端<strong> A B C</strong>,这一点非常重要!!低位是起始点 A,高位时终点 C。</p>\n<p>数据为<strong> 100</strong> 时 ROM 被选中,74138Y4 非端被点亮,<strong>因为 100 正是数字 4</strong>。</p>\n<p>数据为<strong> 101</strong> 时 RAM 被选中,74138Y4 非端被点亮,<strong>因为 101 正是数字 5</strong>。</p>\n<p>接下来再讨论讨论芯片的选择:</p>\n<p>A0 ~ A10 为一个 ROM,一共 11 位,理想是要一个规格为<strong> 2K X 8 位 ROM</strong></p>\n<p>A0 ~ A9 为一个 RAM,一共 10 位,理想是要一个规格为<strong> 1K X 8 位 RAM</strong></p>\n<p>对于 ROM,题中刚好有一个规格为<strong> 2K X 8 位的 ROM 芯片</strong>,拿来便是!</p>\n<p>对于 RAM,题中没有那个规格的我们这里就需要进行扩展,这里我们选择<strong>两片 1K X 4 位的 ROM 芯片</strong>对他进行位扩展就好了。位扩展 位扩展 位扩展,说明它位数不够,数据一次无法写进一个芯片,但是一次可以写进两个芯片。这样就解决了!</p>\n<h1 id=\"总结\"><a class=\"markdownIt-Anchor\" href=\"#总结\">#</a> 总结</h1>\n<p>CPU 与存储器的连接是计算机计算机组成原理中的重要考题,更是期末考试中的重点,看着很复杂的连接图,但其实内在的原理还是很简单的,无非就是:写二进制、选芯片、扩展外带画图连接,本质还是比较容易作的</p>\n",
"tags": [
"计算机组成原理",
"计算机组成原理"
]
},
{
"id": "https://735690757.github.io/Principles-of-computer-composition/booth_algorithm/",
"url": "https://735690757.github.io/Principles-of-computer-composition/booth_algorithm/",
"title": "booth算法",
"date_published": "2023-06-05T11:30:00.000Z",
"content_html": "<h1 id=\"booth-算法\"><a class=\"markdownIt-Anchor\" href=\"#booth-算法\">#</a> Booth 算法</h1>\n<p>这里写点什么捏?就先来点简介吧!!比较法是 Booth 夫妇先提出来的,也称 booth 算法。</p>\n<p>那么!!咱们怎么解题呢,不要担心,其实 booth 算法非常简单,不要被长长的算式所迷惑鸭!!</p>\n<p>接下来就由我来简单快速的叙述一下如何利用 booth 算法去做题!</p>\n<h1 id=\"准备开始\"><a class=\"markdownIt-Anchor\" href=\"#准备开始\">#</a> 准备开始!</h1>\n<p>首先题目里一般会这样给:已知 [x] 补 = xxxxx,[y] 补 = xxxxx,利用 booth 算法求解 [x*y]。</p>\n<p>booth 算法的符号位是<strong>成双成对</strong>的,和你不一样,因为你还没有成双成对哈哈哈哈哈哈(不是)</p>\n<p>另外,我们还需要额外记住的<strong>四个固定形态</strong>:</p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">尾数形态</th>\n<th style=\"text-align:center\">作法</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\">00</td>\n<td style=\"text-align:center\">右移一位</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">01</td>\n<td style=\"text-align:center\">+[x] 补 后 右移一位</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">10</td>\n<td style=\"text-align:center\">+[-x] 补后 右移一位</td>\n</tr>\n<tr>\n<td style=\"text-align:center\">11</td>\n<td style=\"text-align:center\">右移一位</td>\n</tr>\n</tbody>\n</table>\n<h1 id=\"例题一\"><a class=\"markdownIt-Anchor\" href=\"#例题一\">#</a> 例题一</h1>\n<p>已知 [x] 补 = 0.0101,[y] 补 = 1.0101,利用 booth 算法求解 [x*y]</p>\n<p>做题前我们需要做一些准备,首先我们写出双符号位形态的 [x] 补、[-x] 补以及 [y] 补(无需双符号)</p>\n<ul>\n<li>\n<p>[x] 补 = 00.0101</p>\n</li>\n<li>\n<p>[-x] 补 = 11.1011</p>\n</li>\n<li>\n<p>[y] 补 = 1.0101</p>\n</li>\n</ul>\n<p>然后列出如下表格:</p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">部分积</th>\n<th style=\"text-align:center\">乘数</th>\n<th style=\"text-align:center\">辅助</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\">0</td>\n</tr>\n</tbody>\n</table>\n<p>我先写到这,如果有想先试试的小伙伴可以先按照自己的思路去写,还没记起来的的小伙伴们可以继续往下看,一会我还会写出两道例题供大家去练习。</p>\n<p><strong>解答开始!</strong></p>\n<p>辅助位置默认为 0,乘数就是 [y] 补 = 11.0101,部分积初始值也为 0.</p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:right\"></th>\n<th style=\"text-align:center\">部分积</th>\n<th style=\"text-align:center\">乘数</th>\n<th style=\"text-align:center\">辅助</th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:right\"></td>\n<td style=\"text-align:center\">00 0000</td>\n<td style=\"text-align:center\">1010 <strong>1</strong></td>\n<td style=\"text-align:center\"><strong>0</strong></td>\n<td>一次判断</td>\n</tr>\n<tr>\n<td style=\"text-align:right\"><strong>10</strong> 还记得加什么嘛?没错就是加 [-x] 补 +</td>\n<td style=\"text-align:center\">11 1011</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">=</td>\n<td style=\"text-align:center\">11 1011</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">右移</td>\n<td style=\"text-align:center\">11 1101</td>\n<td style=\"text-align:center\">1101 <strong>0</strong></td>\n<td style=\"text-align:center\"><strong>1</strong></td>\n<td>二次判断</td>\n</tr>\n<tr>\n<td style=\"text-align:right\"><strong>01</strong> 还记得加什么嘛?没错就是加 [x] 补 +</td>\n<td style=\"text-align:center\">00 0101</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">=</td>\n<td style=\"text-align:center\">00 0010</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">右移</td>\n<td style=\"text-align:center\">00 0001</td>\n<td style=\"text-align:center\">0110 <strong>1</strong></td>\n<td style=\"text-align:center\"><strong>0</strong></td>\n<td>三次判断</td>\n</tr>\n<tr>\n<td style=\"text-align:right\"><strong>10</strong> 还记得加什么嘛?没错就是加 [-x] 补 +</td>\n<td style=\"text-align:center\">11 1011</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">=</td>\n<td style=\"text-align:center\">11 1100</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">右移</td>\n<td style=\"text-align:center\">11 1110</td>\n<td style=\"text-align:center\">0011 <strong>0</strong></td>\n<td style=\"text-align:center\"><strong>1</strong></td>\n<td>四次判断</td>\n</tr>\n<tr>\n<td style=\"text-align:right\"><strong>01</strong> 还记得加什么嘛?没错就是加 [x] 补 +</td>\n<td style=\"text-align:center\">00 0101</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">=</td>\n<td style=\"text-align:center\">00 0011</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">右移</td>\n<td style=\"text-align:center\">00 0001</td>\n<td style=\"text-align:center\"><strong>1001</strong> <strong>1</strong></td>\n<td style=\"text-align:center\"><strong>0</strong></td>\n<td>五次判断</td>\n</tr>\n<tr>\n<td style=\"text-align:right\"><strong>10</strong> 还记得加什么嘛?没错就是加 [-x] 补 +</td>\n<td style=\"text-align:center\">11 1011</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\"></td>\n<td style=\"text-align:center\"><strong>11 1100</strong></td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p>OK 兄弟们,小数点后有四位,那么我们需要进行五次判断,现在已经完成计算过程了,答案已经呼之欲出了!!</p>\n<p><strong>[x*y] = 1.1100 1001</strong>(如果要双符号为就这样去写:[x*y] = 11.1100 1001)</p>\n<p>总结一下,辅助位配合乘数最后一位作判断操作,00 和 11 只需右移就好,而 01 要 +[x] 补,11 要 +[-x] 补,这样我们就能得到最终的结果了。</p>\n<p>接下来再来一道爽题!!!</p>\n<h1 id=\"例题二\"><a class=\"markdownIt-Anchor\" href=\"#例题二\">#</a> 例题二</h1>\n<p>已知 [x] 补 = 1.0101,[y] 补 = 1.0011,利用 booth 算法求解 [x*y]</p>\n<p>老规矩:</p>\n<ul>\n<li>[x] 补 = 11.0101</li>\n<li>[-x] 补 = 00.1011</li>\n<li>[y] 补 = 1.0011</li>\n</ul>\n<p>列表:</p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:right\"></th>\n<th style=\"text-align:center\">部分积</th>\n<th style=\"text-align:center\">乘数</th>\n<th style=\"text-align:center\">辅助</th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:right\"></td>\n<td style=\"text-align:center\">00 0000</td>\n<td style=\"text-align:center\">1001<strong>1</strong></td>\n<td style=\"text-align:center\"><strong>0</strong></td>\n<td>一次判断</td>\n</tr>\n<tr>\n<td style=\"text-align:right\"><strong>10</strong> +</td>\n<td style=\"text-align:center\">00 1011</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">=</td>\n<td style=\"text-align:center\">00 1011</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">右移</td>\n<td style=\"text-align:center\">00 0101</td>\n<td style=\"text-align:center\">1100 <strong>1</strong></td>\n<td style=\"text-align:center\"><strong>1</strong></td>\n<td>二次判断</td>\n</tr>\n<tr>\n<td style=\"text-align:right\"><strong>11</strong> 右移</td>\n<td style=\"text-align:center\">00 0010</td>\n<td style=\"text-align:center\">1110 <strong>0</strong></td>\n<td style=\"text-align:center\"><strong>1</strong></td>\n<td>三次判断</td>\n</tr>\n<tr>\n<td style=\"text-align:right\"><strong>01</strong> +</td>\n<td style=\"text-align:center\">11 0101</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">=</td>\n<td style=\"text-align:center\">11 0111</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\">右移</td>\n<td style=\"text-align:center\">11 1011</td>\n<td style=\"text-align:center\">1111 <strong>0</strong></td>\n<td style=\"text-align:center\"><strong>0</strong></td>\n<td>四次判断</td>\n</tr>\n<tr>\n<td style=\"text-align:right\"><strong>00</strong> 右移</td>\n<td style=\"text-align:center\">11 1101</td>\n<td style=\"text-align:center\">1111 <strong>1</strong></td>\n<td style=\"text-align:center\"><strong>0</strong></td>\n<td>五次判断</td>\n</tr>\n<tr>\n<td style=\"text-align:right\"><strong>10</strong> +</td>\n<td style=\"text-align:center\">00 1011</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n<tr>\n<td style=\"text-align:right\"></td>\n<td style=\"text-align:center\">00 1000</td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p><strong>第五次判断后无需移动</strong></p>\n<p>答案:0.1000 1111</p>\n<p>怎么样,是不是非常爽,在五次判断中出现了两次数字相同的情况,这时候我们只需要进行右移,无需进行计算。</p>\n<p>最后我在给大家一道练习题,自己练习一下叭~~~</p>\n<h1 id=\"练习\"><a class=\"markdownIt-Anchor\" href=\"#练习\">#</a> 练习</h1>\n<p>已知 [x] 补 = 0.1101,[y] 补 = 0.1011,利用 booth 算法求解 [x*y]</p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:center\">部分积</th>\n<th style=\"text-align:center\">乘数</th>\n<th style=\"text-align:center\">辅助</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\">0</td>\n</tr>\n<tr>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n</tr>\n<tr>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n<td style=\"text-align:center\"></td>\n</tr>\n</tbody>\n</table>\n<h1 id=\"鸣谢\"><a class=\"markdownIt-Anchor\" href=\"#鸣谢\">#</a> 鸣谢</h1>\n<p>感谢 B 站 up 主制作的视频,真的非常不错</p>\n",
"tags": [
"计算机组成原理",
"计算机组成原理"
]
},
{
"id": "https://735690757.github.io/database/DataBase02/",
"url": "https://735690757.github.io/database/DataBase02/",
"title": "数据库设计",
"date_published": "2023-04-18T10:00:00.000Z",
"content_html": "<h1 id=\"数据库设计\"><a class=\"markdownIt-Anchor\" href=\"#数据库设计\">#</a> 数据库设计</h1>\n<h2 id=\"什么是数据库设计\"><a class=\"markdownIt-Anchor\" href=\"#什么是数据库设计\">#</a> 什么是数据库设计</h2>\n<p>数据库设计是指根据需求分析和业务流程,设计出符合应用需求的数据库结构和表结构的过程。通常包括以下几个步骤:</p>\n<ol>\n<li>需求分析:对应用的功能和数据进行分析,确定应用所需的数据和数据间的关系,明确数据的属性和约束条件。</li>\n<li>概念设计:将需求分析的结果转化为概念模型,包括实体 - 关系模型和 E-R 图等,以及各个实体之间的联系、属性及约束等。</li>\n<li>逻辑设计:将概念模型转化为逻辑模型,包括表的定义、属性定义、关键字、完整性规则等,确定表与表之间的联系,构建数据模型。</li>\n<li>物理设计:在逻辑设计的基础上,结合具体的数据库管理系统(如 MySQL、Oracle、SQL Server 等),考虑实现方式和优化策略,设计出物理存储结构,包括数据表的存储方式、索引、分区等等。</li>\n</ol>\n<p>在数据库设计的过程中,需要遵循以下原则:</p>\n<ol>\n<li>数据库的设计应该符合应用需求和业务流程,具有可扩展性、可维护性和可靠性。</li>\n<li>数据库应该遵循数据规范化的原则,减少数据冗余和数据异常,提高数据存储效率。</li>\n<li>数据库设计应该考虑数据的完整性和安全性,采取适当的权限管理和数据备份策略,保证数据的安全性和可靠性。</li>\n<li>数据库设计应该遵循一定的命名规范,使数据库的结构清晰易懂,便于后期的维护和管理。</li>\n</ol>\n<p>综上所述,数据库设计是一个综合性较强的任务,需要综合考虑多方面的因素,才能设计出符合应用需求和业务流程,高效可靠的数据库结构。</p>\n<h2 id=\"数据库设计过程\"><a class=\"markdownIt-Anchor\" href=\"#数据库设计过程\">#</a> 数据库设计过程</h2>\n<ol>\n<li>需求分析</li>\n<li>概念结构设计</li>\n<li>逻辑结构设计</li>\n<li>数据库物理设计</li>\n<li>数据库实施</li>\n<li>数据库运行与维护</li>\n</ol>\n<h2 id=\"数据库设计过程各个阶段上的设计描述\"><a class=\"markdownIt-Anchor\" href=\"#数据库设计过程各个阶段上的设计描述\">#</a> 数据库设计过程各个阶段上的设计描述</h2>\n<p>数据库设计过程一般包括以下几个阶段:</p>\n<ol>\n<li>需求分析阶段:在需求分析阶段,需要进行数据需求的调研和收集,明确系统需要存储的数据、数据之间的关系以及对数据的操作等,设计描述的主要内容包括数据流图、数据字典等。</li>\n<li>概念设计阶段:在概念设计阶段,需要将需求分析得到的数据需求转化为概念模型,设计描述的主要内容包括实体关系图(ER 图)。</li>\n<li>逻辑设计阶段:在逻辑设计阶段,需要将概念模型转化为具体的逻辑模型,设计描述的主要内容包括关系模式、属性、主键、外键、索引等。</li>\n<li>物理设计阶段:在物理设计阶段,需要将逻辑模型转化为数据库实现模型,设计描述的主要内容包括表结构、存储方式、物理索引等。</li>\n</ol>\n<p>在每个阶段中,设计描述的内容都不同,但都是在将需求转化为具体的数据库结构的过程中所必需的,而且在设计描述的过程中,需要对需求进行细致的分析和理解,以保证设计结构的正确性和实用性。</p>\n",
"tags": [
"数据库",
"数据库"
]
},
{
"id": "https://735690757.github.io/database/DataBase01/",
"url": "https://735690757.github.io/database/DataBase01/",
"title": "DB中的范式",
"date_published": "2023-04-11T13:16:00.000Z",
"content_html": "<h1 id=\"数据库范式\"><a class=\"markdownIt-Anchor\" href=\"#数据库范式\">#</a> 数据库范式</h1>\n<h2 id=\"什么是数据库范式\"><a class=\"markdownIt-Anchor\" href=\"#什么是数据库范式\">#</a> 什么是数据库范式</h2>\n<p>数据库范式(Normalization)是一种设计关系型数据库的方法,它旨在减少数据冗余,提高数据的一致性和可靠性,避免数据修改时出现异常。数据库范式通常分为一到五个级别,每个级别对应一组设计规则。</p>\n<p>范式越高,数据冗余越少,数据一致性和可靠性越高。但是,范式过高也可能会带来一些问题,如增加了数据库的复杂性和查询的开销,需要根据实际应用场景来确定使用哪个范式。</p>\n<h2 id=\"层级分类\"><a class=\"markdownIt-Anchor\" href=\"#层级分类\">#</a> 层级分类</h2>\n<h3 id=\"1nf第一范式\"><a class=\"markdownIt-Anchor\" href=\"#1nf第一范式\">#</a> 1NF(第一范式)</h3>\n<p>关系模式中的所有属性都是原子性的,即不可再分。</p>\n<h3 id=\"2nf第二范式\"><a class=\"markdownIt-Anchor\" href=\"#2nf第二范式\">#</a> 2NF(第二范式)</h3>\n<p>关系模式必须满足第一范式,且不存在非关键字属性对主键的部分依赖。</p>\n<h3 id=\"3nf第三范式\"><a class=\"markdownIt-Anchor\" href=\"#3nf第三范式\">#</a> 3NF(第三范式)</h3>\n<p>关系模式必须满足第二范式,且不存在非关键字属性对其他非关键字属性的传递依赖。</p>\n<h3 id=\"bcnfboyce-codd-范式\"><a class=\"markdownIt-Anchor\" href=\"#bcnfboyce-codd-范式\">#</a> BCNF(Boyce-Codd 范式)</h3>\n<p>关系模式必须满足第一范式,且不存在非主属性对主属性的非平凡依赖关系。</p>\n<h3 id=\"4nf第四范式\"><a class=\"markdownIt-Anchor\" href=\"#4nf第四范式\">#</a> 4NF(第四范式)</h3>\n<p>关系模式必须满足第三范式,且不存在多值依赖。</p>\n<h3 id=\"5nf第五范式\"><a class=\"markdownIt-Anchor\" href=\"#5nf第五范式\">#</a> 5NF(第五范式)</h3>\n<p>关系模式必须满足第四范式,且不存在连接依赖。</p>\n<h2 id=\"小题目\"><a class=\"markdownIt-Anchor\" href=\"#小题目\">#</a> 小题目</h2>\n<p>让我们通过一些题目来感受一下吧!!</p>\n<h3 id=\"ex1\"><a class=\"markdownIt-Anchor\" href=\"#ex1\">#</a> Ex1</h3>\n<blockquote>\n<p>设有关系 R(工号,姓名,工种,定额),则 R 是属于第 2 范式,将其转化为第三范式</p>\n</blockquote>\n<p>根据关系 R(工号,姓名,工种,定额),我们可以看出工号和姓名是候选键,因为它们可以唯一地标识每个元组。同时,我们也可以看出工种和定额这两个属性完全依赖于候选键,因此关系 R 符合 2NF 的要求。</p>\n<p>现在我们来考虑将 R 转化为 3NF 的过程。根据 3NF 的要求,我们需要消除任何非主属性对主键的传递依赖。因此,我们需要检查每个非主属性是否直接依赖于主键,或者是直接依赖于其他非主属性。</p>\n<p>在关系 R 中,我们可以发现定额属性直接依赖于工种属性,而工种属性并不是主键的一部分。因此,我们可以将定额和工种拆分到一个新的关系中,以消除定额对于工种的传递依赖,从而使得关系 R 满足 3NF 的要求。</p>\n<p>拆分后的两个关系如下:</p>\n<ul>\n<li>R1(工号,姓名,工种):该关系包含了工号、姓名和工种三个属性,其中工号和姓名作为候选键,工种是一个非主属性,但它直接依赖于主键。因此,关系 R1 符合 2NF 和 3NF 的要求。</li>\n<li>R2(工种,定额):该关系包含了工种和定额两个属性,其中工种作为主键,定额是一个非主属性,但它直接依赖于主键。因此,关系 R2 符合 2NF 和 3NF 的要求。</li>\n</ul>\n<p>最终,我们将关系 R 转化为两个符合 3NF 的关系 R1 和 R2,符合 3NF 的要求。</p>\n<h3 id=\"ex2\"><a class=\"markdownIt-Anchor\" href=\"#ex2\">#</a> Ex2</h3>\n<blockquote>\n<p>设有关系 STUDENT (S#,SNAME,SDEPT,MNAME,CNAME,GRADE),S#,CNAME 为候选码,设关系中有如下函数依赖:</p>\n<p>S#,CNAME→SNAME,SDEPT,MNAME<br>\nS#→SNAME,SDEPT,MNAME<br>\nS#,CNAME→GRADE<br>\nSDEPT→MNAME<br>\n 试求下列问题:<br>\n(1)关系 STUDENT 属于第几范式?<br>\n(2)如果关系 STUDENT 不属于 BCNF,请将关系 STUDENT 逐步分解为 BCNF。<br>\n要求:写出达到每一级范式的分解过程,并指明消除什么类型的函数依赖。</p>\n</blockquote>\n<p>(1)1NF</p>\n<p>(2)首先消除非主属性对候选码的部分依赖,即消除部分函数依赖</p>\n<p><strong>(S#,CNAME)->(SNAME,SDEPT,MNAME)</strong></p>\n<p>R 分解为:</p>\n<p><strong>R1(S#,SNAME,SDEPT,MNAME)</strong></p>\n<p><strong>R2(S#,CNAME,GRADE)</strong></p>\n<p>R 至此分解为 2NF</p>\n<p>此时 R1 中存在非主属性对候选码的传递依赖,即消除传递依赖</p>\n<p><strong>(S#)->(SDEPT)</strong></p>\n<p><strong>(SDEPT)->(MNAME)</strong></p>\n<p>R1 分解为:</p>\n<p><strong>R11(S#,SNAME,SDEPT)</strong></p>\n<p><strong>R12(SDEPT,MNAME)</strong></p>\n<p>R1 至此分解为 3NF</p>\n<p>此时 R11,R12,R2 可以得出的函数依赖:</p>\n<p><strong>(S#,CNAME)->(GRADE)</strong></p>\n<p><strong>(S#)->(SNAME),(S#)->(SDEPT)</strong></p>\n<p><strong>(SDEPT)->(MNAME)</strong></p>\n<p> 由此可以看出,数据表中的每个非主属性都完全依赖于候选键,即每个非主属性都不只依赖于候选键的一部分,且非主属性无法决定另一个非主属性,即不存在非平凡函数依赖。</p>\n<p> 上述关系表 R11,R12,R2 满足 BCNF</p>\n<h3 id=\"ex3\"><a class=\"markdownIt-Anchor\" href=\"#ex3\">#</a> Ex3</h3>\n<blockquote>\n<p>一个关系模式不属于第二范式可能会产生 ()、() 和 ( ) 等几个问题,解决的办法是 ( )。</p>\n</blockquote>\n<ul>\n<li>\n<p><em>第一空:</em></p>\n<p>插入异常</p>\n</li>\n<li>\n<p><em>第二空:</em></p>\n<p>删除异常</p>\n</li>\n<li>\n<p><em>第三空:</em></p>\n<p>修改异常</p>\n</li>\n<li>\n<p><em>第四空:</em></p>\n<p>投影分解</p>\n</li>\n</ul>\n<h2 id=\"关键词\"><a class=\"markdownIt-Anchor\" href=\"#关键词\">#</a> 关键词</h2>\n<h3 id=\"候选码和非主属性\"><a class=\"markdownIt-Anchor\" href=\"#候选码和非主属性\">#</a> 候选码和非主属性</h3>\n<p>候选码和非主属性是关系数据库中的两个概念,它们之间有一定的关系。</p>\n<p>候选码(Candidate Key)指的是能够唯一标识关系模式中每一条记录的属性集合。一个关系模式可能有多个候选码,但是其中只有一个会被选择作为主键(Primary Key)来标识每一条记录。通常情况下,主键会被用来建立关系模式之间的联系,因此选择一个恰当的候选码作为主键是关系数据库设计中的重要步骤。</p>\n<p>非主属性指的是关系模式中除了主键之外的属性。一个关系模式可能包含多个非主属性,它们之间可以存在依赖关系。例如,一个关系模式 R(A,B,C)中,如果存在函数依赖 A→B,则 B 是非主属性。</p>\n<p>候选码和非主属性之间的关系在于,一个候选码包含了所有的主属性,而非主属性可能依赖于主属性,也可能存在依赖于其他非主属性的情况。在进行关系数据库设计时,我们需要通过确定候选码和依赖关系来规范化关系模式,从而消除数据冗余和不一致性的问题。通常情况下,我们会选择最小的候选码作为主键,并确保所有非主属性都完全依赖于主键,以保证数据的完整性和一致性。</p>\n<h3 id=\"平凡依赖关系\"><a class=\"markdownIt-Anchor\" href=\"#平凡依赖关系\">#</a> 平凡依赖关系</h3>\n<p>平凡依赖关系是指对于一个属性集合 X,在一个关系 R 中如果 X 的任意超集都可以唯一地确定 X,那么 X 对于 R 就是平凡的依赖。例如,在一个关系 R(A, B, C),如果存在函数依赖 A→A,那么 A 对于 R 来说是一个平凡依赖。因为 A 的任意超集都可以唯一地确定 A 本身,即 A 已经包含了它所依赖的属性。</p>\n<p>可以这样理解,一个属性集合如果能够唯一地确定自己,那么它就是平凡的依赖。例如,在一个关系 R(A, B, C),如果存在函数依赖 A→A,那么 A 对于 R 来说是一个平凡依赖,因为属性集合 A 已经包含了它所依赖的属性 A 本身,即 A 已经能够唯一地确定自己。而非平凡的依赖是指一个属性集合不能唯一地确定自己,需要依赖于其他属性才能确定自己,例如在关系 R(A, B, C)中,存在函数依赖 A→B,B 就是一个非平凡依赖,因为 B 不能唯一地确定自己,需要依赖于 A 才能确定。</p>\n<h3 id=\"传递依赖\"><a class=\"markdownIt-Anchor\" href=\"#传递依赖\">#</a> 传递依赖</h3>\n<p>传递依赖(Transitive Dependency)指的是一个非主属性依赖于另一个非主属性的非主属性。例如,一个关系模式 R(A,B,C)中,如果存在函数依赖 A→B 和 B→C,则 C 对 A 存在传递依赖。这种情况下,如果我们要更新 A 的值,就会导致 C 的值也随之改变,从而引起数据不一致的问题。</p>\n",
"tags": [
"数据库",
"数据库"
]
}
]
}