Conflicts:
	.idea/workspace.xml
pull/6/head
yuanguangxin 5 years ago
commit d8b5f480aa

@ -19,14 +19,18 @@
<select />
</component>
<component name="ChangeListManager">
<list default="true" id="af7ffdf2-4ddc-4ed6-8222-60ed5acbc2ed" name="Default Changelist" comment="add q581">
<list default="true" id="af7ffdf2-4ddc-4ed6-8222-60ed5acbc2ed" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Rocket.md" beforeDir="false" afterPath="$PROJECT_DIR$/Rocket.md" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="CodeStyleSettingsInfer">
<option name="done" value="true" />
</component>
<component name="DatabaseView">
<option name="SHOW_INTERMEDIATE" value="true" />
<option name="GROUP_DATA_SOURCES" value="true" />
@ -52,6 +56,9 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="UPDATE_TYPE" value="MERGE" />
</component>
<component name="ProjectCodeStyleSettingsMigration">
<option name="version" value="1" />
</component>
<component name="ProjectId" id="1VejAt63XWcMUQr7gJbMHyEoS6Q" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
@ -83,11 +90,11 @@
</component>
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="链表操作.q25_K个一组翻转链表" />
<recent name="contest" />
<recent name="链表操作.q61_旋转链表" />
<recent name="链表操作.q19_删除链表的倒数第N个节点" />
<recent name="递归.q104_二叉树的最大深度" />
<recent name="快慢指针遍历.q876_链表的中间结点" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/hash相关" />
@ -96,13 +103,20 @@
<recent name="$PROJECT_DIR$/src/q206/f1" />
</key>
</component>
<component name="RunManager" selected="Application.Test (1)">
<configuration name="Solution (1)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="数组操作.q581_最短无序连续子数组.Solution" />
<component name="RunManager" selected="Application.Test">
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Main" />
<module name="LeetCode" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Solution (2)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="动态规划.q70_爬楼梯.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="数组操作.q581_最短无序连续子数组.*" />
<option name="PATTERN" value="动态规划.q70_爬楼梯.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -110,12 +124,12 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Solution (2)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="动态规划.q70_爬楼梯.Solution" />
<configuration name="Solution (3)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="contest.q4.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="动态规划.q70_爬楼梯.*" />
<option name="PATTERN" value="contest.q4.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -175,19 +189,6 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Test (1)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="其他.tx.Test" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="其他.tx.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Test" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="其他.Test" />
<module name="LeetCode" />
@ -203,11 +204,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Test (1)" />
<item itemvalue="Application.Solution (1)" />
<item itemvalue="Application.Test" />
<item itemvalue="Application.Solution" />
<item itemvalue="Application.Solution (2)" />
<item itemvalue="Application.Main" />
<item itemvalue="Application.Solution (3)" />
</list>
</recent_temporary>
</component>
@ -276,18 +277,9 @@
<workItem from="1591713471095" duration="2944000" />
<workItem from="1591758584495" duration="3000" />
<workItem from="1592230200964" duration="1933000" />
<workItem from="1592291352584" duration="7930000" />
<workItem from="1592386773785" duration="664000" />
<workItem from="1592484855258" duration="5544000" />
<workItem from="1592798003146" duration="15000" />
<workItem from="1592810015972" duration="11339000" />
</task>
<task id="LOCAL-00025" summary="update Rocket.md">
<created>1581858428131</created>
<option name="number" value="00025" />
<option name="presentableId" value="LOCAL-00025" />
<option name="project" value="LOCAL" />
<updated>1581858428131</updated>
<workItem from="1592291352584" duration="6590000" />
<workItem from="1592577669343" duration="2000" />
<workItem from="1592881051365" duration="423000" />
</task>
<task id="LOCAL-00026" summary="rename package">
<created>1581954761859</created>
@ -612,24 +604,31 @@
<updated>1591717167748</updated>
</task>
<task id="LOCAL-00072" summary="update">
<created>1592303771862</created>
<created>1592388297996</created>
<option name="number" value="00072" />
<option name="presentableId" value="LOCAL-00072" />
<option name="project" value="LOCAL" />
<updated>1592303771862</updated>
<updated>1592388297996</updated>
</task>
<task id="LOCAL-00073" summary="add q581">
<created>1592834370217</created>
<task id="LOCAL-00073" summary="update">
<created>1592881788620</created>
<option name="number" value="00073" />
<option name="presentableId" value="LOCAL-00073" />
<option name="project" value="LOCAL" />
<updated>1592834370220</updated>
<updated>1592881788621</updated>
</task>
<task id="LOCAL-00074" summary="update">
<created>1592881815955</created>
<option name="number" value="00074" />
<option name="presentableId" value="LOCAL-00074" />
<option name="project" value="LOCAL" />
<updated>1592881815955</updated>
</task>
<option name="localTasksCounter" value="74" />
<option name="localTasksCounter" value="75" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="2" />
<option name="version" value="1" />
</component>
<component name="Vcs.Log.History.Properties">
<option name="COLUMN_ORDER">
@ -671,19 +670,21 @@
</entry>
<entry key="MAIN">
<value>
<State />
<State>
<option name="COLUMN_ORDER" />
</State>
</value>
</entry>
</map>
</option>
<option name="OPEN_GENERIC_TABS">
<map>
<entry key="1" value="TOOL_WINDOW" />
</map>
<option name="OPEN_TABS">
<set>
<option value="1" />
</set>
</option>
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="add q736" />
<MESSAGE value="增加操作系统相关问题" />
<MESSAGE value="增加JVM相关问题" />
<MESSAGE value="add q141/q202/q258" />
@ -708,56 +709,54 @@
<MESSAGE value="增加问题" />
<MESSAGE value="add q78" />
<MESSAGE value="update" />
<MESSAGE value="add q581" />
<option name="LAST_COMMIT_MESSAGE" value="add q581" />
<option name="LAST_COMMIT_MESSAGE" value="update" />
</component>
<component name="WindowStateProjectService">
<state x="458" y="204" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1587221348872">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="458" y="204" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1440.900@0.0.1440.900" timestamp="1587221348872" />
<state x="404" y="60" key="CommitChangelistDialog2" timestamp="1591633493160">
<state x="404" y="60" key="CommitChangelistDialog2" timestamp="1592882002208">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="303" y="50" key="CommitChangelistDialog2/0.0.1440.900@0.0.1440.900" timestamp="1588749779133" />
<state x="404" y="60" key="CommitChangelistDialog2/0.0.1920.1080@0.0.1920.1080" timestamp="1591633493160" />
<state x="218" y="104" width="1317" height="796" key="DiffContextDialog" timestamp="1592882299251">
<screen x="0" y="0" width="2194" height="1194" />
<state x="303" y="50" key="CommitChangelistDialog2/0.0.1440.900@0.0.1440.900" timestamp="1592388297859" />
<state x="404" y="60" key="CommitChangelistDialog2/0.0.1920.1080@0.0.1920.1080" timestamp="1592882002208" />
<state x="191" y="94" width="1536" height="864" key="DiffContextDialog" timestamp="1592882219151">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="143" y="78" width="1152" height="720" key="DiffContextDialog/0.0.1440.900@0.0.1440.900" timestamp="1588749770793" />
<state x="191" y="94" key="DiffContextDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1591262490778" />
<state x="218" y="104" width="1317" height="796" key="DiffContextDialog/0.0.2194.1194@0.0.2194.1194" timestamp="1592882299251" />
<state x="143" y="78" width="1152" height="720" key="DiffContextDialog/0.0.1440.900@0.0.1440.900" timestamp="1592386883631" />
<state x="191" y="94" width="1536" height="864" key="DiffContextDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1592882219151" />
<state x="143" y="78" width="1152" height="720" key="DiffContextDialog/0.23.1440.797@0.23.1440.797" timestamp="1588303139733" />
<state width="2151" height="297" key="GridCell.Tab.0.bottom" timestamp="1592840996856">
<state width="2151" height="333" key="GridCell.Tab.0.bottom" timestamp="1592301525961">
<screen x="0" y="0" width="2194" height="1194" />
</state>
<state width="1398" height="204" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1587225087588" />
<state width="1878" height="380" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1591595634376" />
<state width="2151" height="297" key="GridCell.Tab.0.bottom/0.0.2194.1194@0.0.2194.1194" timestamp="1592840996856" />
<state width="2151" height="333" key="GridCell.Tab.0.bottom/0.0.2194.1194@0.0.2194.1194" timestamp="1592301525961" />
<state width="1398" height="245" key="GridCell.Tab.0.bottom/0.23.1440.797@0.23.1440.797" timestamp="1587203529573" />
<state width="1878" height="359" key="GridCell.Tab.0.bottom/0.23.1920.977@0.23.1920.977" timestamp="1591364244398" />
<state width="2151" height="297" key="GridCell.Tab.0.center" timestamp="1592840996856">
<state width="2151" height="333" key="GridCell.Tab.0.center" timestamp="1592301525961">
<screen x="0" y="0" width="2194" height="1194" />
</state>
<state width="1398" height="204" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1587225087587" />
<state width="1878" height="380" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1591595634219" />
<state width="2151" height="297" key="GridCell.Tab.0.center/0.0.2194.1194@0.0.2194.1194" timestamp="1592840996856" />
<state width="2151" height="333" key="GridCell.Tab.0.center/0.0.2194.1194@0.0.2194.1194" timestamp="1592301525961" />
<state width="1398" height="245" key="GridCell.Tab.0.center/0.23.1440.797@0.23.1440.797" timestamp="1587203529571" />
<state width="1878" height="359" key="GridCell.Tab.0.center/0.23.1920.977@0.23.1920.977" timestamp="1591364244398" />
<state width="2151" height="297" key="GridCell.Tab.0.left" timestamp="1592840996856">
<state width="2151" height="333" key="GridCell.Tab.0.left" timestamp="1592301525961">
<screen x="0" y="0" width="2194" height="1194" />
</state>
<state width="1398" height="204" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1587225087586" />
<state width="1878" height="380" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1591595634218" />
<state width="2151" height="297" key="GridCell.Tab.0.left/0.0.2194.1194@0.0.2194.1194" timestamp="1592840996856" />
<state width="2151" height="333" key="GridCell.Tab.0.left/0.0.2194.1194@0.0.2194.1194" timestamp="1592301525961" />
<state width="1398" height="245" key="GridCell.Tab.0.left/0.23.1440.797@0.23.1440.797" timestamp="1587203529570" />
<state width="1878" height="359" key="GridCell.Tab.0.left/0.23.1920.977@0.23.1920.977" timestamp="1591364244397" />
<state width="2151" height="297" key="GridCell.Tab.0.right" timestamp="1592840996856">
<state width="2151" height="333" key="GridCell.Tab.0.right" timestamp="1592301525961">
<screen x="0" y="0" width="2194" height="1194" />
</state>
<state width="1398" height="204" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1587225087587" />
<state width="1878" height="380" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1591595634375" />
<state width="2151" height="297" key="GridCell.Tab.0.right/0.0.2194.1194@0.0.2194.1194" timestamp="1592840996856" />
<state width="2151" height="333" key="GridCell.Tab.0.right/0.0.2194.1194@0.0.2194.1194" timestamp="1592301525961" />
<state width="1398" height="245" key="GridCell.Tab.0.right/0.23.1440.797@0.23.1440.797" timestamp="1587203529572" />
<state width="1878" height="359" key="GridCell.Tab.0.right/0.23.1920.977@0.23.1920.977" timestamp="1591364244398" />
<state width="1878" height="359" key="GridCell.Tab.1.bottom" timestamp="1591364244400">
@ -784,21 +783,21 @@
<state width="1398" height="204" key="GridCell.Tab.1.right/0.0.1440.900@0.0.1440.900" timestamp="1587225087589" />
<state width="1878" height="359" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1591355457120" />
<state width="1878" height="359" key="GridCell.Tab.1.right/0.23.1920.977@0.23.1920.977" timestamp="1591364244399" />
<state x="657" y="230" key="MultipleFileMergeDialog" timestamp="1592834386039">
<screen x="0" y="0" width="2194" height="1194" />
<state x="575" y="208" key="MultipleFileMergeDialog" timestamp="1592881800291">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="431" y="173" key="MultipleFileMergeDialog/0.0.1440.900@0.0.1440.900" timestamp="1588302773046" />
<state x="657" y="230" key="MultipleFileMergeDialog/0.0.2194.1194@0.0.2194.1194" timestamp="1592834386039" />
<state x="575" y="208" key="MultipleFileMergeDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1592881800291" />
<state x="221" y="63" key="SettingsEditor" timestamp="1585223890241">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="221" y="63" key="SettingsEditor/0.0.1440.900@0.0.1440.900" timestamp="1585223890241" />
<state x="488" y="252" key="Vcs.Push.Dialog.v2" timestamp="1592834418206">
<screen x="0" y="0" width="2194" height="1194" />
<state x="427" y="228" key="Vcs.Push.Dialog.v2" timestamp="1592882003601">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="320" y="190" key="Vcs.Push.Dialog.v2/0.0.1440.900@0.0.1440.900" timestamp="1588749781144" />
<state x="427" y="228" key="Vcs.Push.Dialog.v2/0.0.1920.1080@0.0.1920.1080" timestamp="1591633495184" />
<state x="488" y="252" key="Vcs.Push.Dialog.v2/0.0.2194.1194@0.0.2194.1194" timestamp="1592834418206" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2/0.0.1440.900@0.0.1440.900" timestamp="1592388299499" />
<state x="427" y="228" key="Vcs.Push.Dialog.v2/0.0.1920.1080@0.0.1920.1080" timestamp="1592882003601" />
<state x="488" y="252" key="Vcs.Push.Dialog.v2/0.0.2194.1194@0.0.2194.1194" timestamp="1591717170083" />
<state x="100" y="100" width="1240" height="700" key="com.intellij.history.integration.ui.views.FileHistoryDialog" timestamp="1587219014962">
<screen x="0" y="23" width="1440" height="797" />
</state>
@ -816,14 +815,11 @@
</state>
<state x="378" y="207" width="683" height="486" key="find.popup/0.0.1440.900@0.0.1440.900" timestamp="1586846937826" />
<state x="504" y="248" width="911" height="584" key="find.popup/0.0.1920.1080@0.0.1920.1080" timestamp="1591635370753" />
<state x="791" y="384" key="git4idea.merge.GitPullDialog" timestamp="1592882290972">
<screen x="0" y="0" width="2194" height="1194" />
</state>
<state x="791" y="384" key="git4idea.merge.GitPullDialog/0.0.2194.1194@0.0.2194.1194" timestamp="1592882290972" />
<state x="754" y="279" key="run.anything.popup" timestamp="1592830659233">
<screen x="0" y="0" width="2194" height="1194" />
<state x="638" y="338" key="git4idea.merge.GitPullDialog" timestamp="1592881849587">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="754" y="279" key="run.anything.popup/0.0.2194.1194@0.0.2194.1194" timestamp="1592830659233" />
<state x="479" y="282" key="git4idea.merge.GitPullDialog/0.0.1440.900@0.0.1440.900" timestamp="1592386920559" />
<state x="638" y="338" key="git4idea.merge.GitPullDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1592881849587" />
<state x="385" y="196" width="670" height="676" key="search.everywhere.popup" timestamp="1587219643331">
<screen x="0" y="0" width="1440" height="900" />
</state>

@ -2,7 +2,7 @@
## ZooKeeper
### CAP定理
一个分布式系统不可能在满足分区容错性P的情况下同时满足一致性C和可用性A:。在此ZooKeeper保证的是CPZooKeeper不能保证每次服务请求的可用性在极端环境下ZooKeeper可能会丢弃一些请求消费者程序需要重新请求才能获得结果。另外在进行leader选举时集群都是不可用所以说ZooKeeper不能保证服务可用性。
一个分布式系统不可能在满足分区容错性P的情况下同时满足一致性C和可用性A。在此ZooKeeper保证的是CPZooKeeper不能保证每次服务请求的可用性在极端环境下ZooKeeper可能会丢弃一些请求消费者程序需要重新请求才能获得结果。另外在进行leader选举时集群都是不可用所以说ZooKeeper不能保证服务可用性。
### BASE理论
@ -719,6 +719,10 @@ Kafka最初考虑的问题是customer应该从brokes拉取消息还是brokers
4. 进程间不会相互影响,一个线程挂掉将导致整个进程挂掉。
5. 系统在运行的时候会为每个进程分配不同的内存空间而对线程而言除了CPU外系统不会为线程分配内存线程所使用的资源来自其所属进程的资源线程组之间只能共享资源。
### 多线程和单线程
线程不是越多越好假如你的业务逻辑全部是计算型的CPU密集型,不涉及到IO并且只有一个核心。那肯定一个线程最好多一个线程就多一点线程切换的计算CPU不能完完全全的把计算能力放在业务计算上面线程越多就会造成CPU利用率用在业务计算的时间/总的时间下降。但是在WEB场景下业务并不是CPU密集型任务而是IO密集型的任务一个线程是不合适如果一个线程在等待数据时把CPU的计算能力交给其他线程这样也能充分的利用CPU资源。但是线程数量也要有个限度一般线程数有一个公式最佳启动线程数=[任务执行时间/(任务执行时间-IO等待时间)]*CPU内核数超过这个数量CPU要进行多余的线程切换从而浪费计算能力低于这个数量CPU要进行IO等待从而造成计算能力不饱和。总之就是要尽可能的榨取CPU的计算能力。如果你的CPU处于饱和状态并且没有多余的线程切换浪费那么此时就是你服务的完美状态如果再加大并发量势必会造成性能上的下降。
### 进程的组成部分
进程由进程控制块PCB、程序段、数据段三部分组成。
@ -739,6 +743,29 @@ Kafka最初考虑的问题是customer应该从brokes拉取消息还是brokers
4. 信号量:不能传递复杂消息,只能用来同步。
5. 共享内存区:能够很容易控制容量,速度快,但要保持同步,比如一个进程在写的时候,另一个进程要注意读写的问题,相当于线程中的线程安全,当然,共享内存区同样可以用作线程间通讯,不过没这个必要,线程间本来就已经共享了同一进程内的一块内存。
### 内存管理有哪几种方式
1. 块式管理把主存分为一大块、一大块的当所需的程序片断不在主存时就分配一块主存空间把程序片断load入主存就算所需的程序片度只有几个字节也只能把这一块分配给它。这样会造成很大的浪费平均浪费了50的内存空间但是易于管理。
2. 页式管理:把主存分为一页一页的,每一页的空间要比一块一块的空间小很多,显然这种方法的空间利用率要比块式管理高很多。
3. 段式管理:把主存分为一段一段的,每一段的空间又要比一页一页的空间小很多,这种方法在空间利用率上又比页式管理高很多,但是也有另外一个缺点。一个程序片断可能会被分为几十段,这样很多时间就会被浪费在计算每一段的物理地址上。
4. 段页式管理结合了段式管理和页式管理的优点。将程序分成若干段每个段分成若干页。段页式管理每取一数据要访问3次内存。
### 页面置换算法
1. 最佳置换算法OPT只具有理论意义的算法用来评价其他页面置换算法。置换策略是将当前页面中在未来最长时间内不会被访问的页置换出去。
2. 先进先出置换算法FIFO简单粗暴的一种置换算法没有考虑页面访问频率信息。每次淘汰最早调入的页面。
3. 最近最久未使用算法LRU算法赋予每个页面一个访问字段用来记录上次页面被访问到现在所经历的时间t每次置换的时候把t值最大的页面置换出去(实现方面可以采用寄存器或者栈的方式实现)。
4. 时钟算法clock(也被称为是最近未使用算法NRU)页面设置一个访问位并将页面链接为一个环形队列页面被访问的时候访问位设置为1。页面置换的时候如果当前指针所指页面访问为为0那么置换否则将其置为0循环直到遇到一个访问为位0的页面。
5. 改进型Clock算法在Clock算法的基础上添加一个修改位替换时根究访问位和修改位综合判断。优先替换访问位和修改位都是0的页面其次是访问位为0修改位为1的页面。
6. LFU最少使用算法LFU设置寄存器记录页面被访问次数每次置换的时候置换当前访问次数最少的。
### 操作系统中进程调度策略有哪几种
1. 先来先服务调度算法FCFS队列实现非抢占先请求CPU的进程先分配到CPU可以作为作业调度算法也可以作为进程调度算法按作业或者进程到达的先后顺序依次调度对于长作业比较有利.
2. 最短作业优先调度算法SJF作业调度算法算法从就绪队列中选择估计时间最短的作业进行处理直到得出结果或者无法继续执行平均等待时间最短但难以知道下一个CPU区间长度缺点不利于长作业未考虑作业的重要性运行时间是预估的并不靠谱.
3. 优先级调度算法(可以是抢占的,也可以是非抢占的)优先级越高越先分配到CPU相同优先级先到先服务存在的主要问题是低优先级进程无穷等待CPU会导致无穷阻塞或饥饿.
4. 时间片轮转调度算法(可抢占的)按到达的先后对进程放入队列中然后给队首进程分配CPU时间片时间片用完之后计时器发出中断暂停当前进程并将其放到队列尾部循环 ;队列中没有进程被分配超过一个时间片的CPU时间除非它是唯一可运行的进程。如果进程的CPU区间超过了一个时间片那么该进程就被抢占并放回就绪队列。
### 死锁的4个必要条件
1. 互斥条件:一个资源每次只能被一个线程使用;
@ -835,7 +862,50 @@ void quick_sort(int a[], int low, int high){
}
```
5. 堆排序假设序列有n个元素,先将这n建成大顶堆然后取堆顶元素与序列第n个元素交换然后调整前n-1元素使其重新成为堆然后再取堆顶元素与第n-1个元素交换再调整前n-2个元素...直至整个序列有序。
5. 堆排序将待排序序列构造成一个大顶堆此时整个序列的最大值就是堆顶的根节点。将其与末尾元素进行交换此时末尾就为最大值。然后将剩余n-1个元素重新构造成一个堆这样会得到n个元素的次小值。如此反复执行便能得到一个有序序列了。
```java
public class Test {
public void sort(int[] arr) {
for (int i = arr.length / 2 - 1; i >= 0; i--) {
adjustHeap(arr, i, arr.length);
}
for (int j = arr.length - 1; j > 0; j--) {
swap(arr, 0, j);
adjustHeap(arr, 0, j);
}
}
public void adjustHeap(int[] arr, int i, int length) {
int temp = arr[i];
for (int k = i * 2 + 1; k < length; k = k * 2 + 1) {
if (k + 1 < length && arr[k] < arr[k + 1]) {
k++;
}
if (arr[k] > temp) {
arr[i] = arr[k];
i = k;
} else {
break;
}
}
arr[i] = temp;
}
public void swap(int[] arr, int a, int b) {
int temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
public static void main(String[] args) {
int[] arr = {9, 8, 7, 6, 5, 4, 3, 2, 1};
new Test().sort(arr);
System.out.println(Arrays.toString(arr));
}
}
```
6. 希尔排序:先将整个待排记录序列分割成为若干子序列分别进行直接插入排序,待整个序列中的记录基本有序时再对全体记录进行一次直接插入排序。
7. 归并排序:把有序表划分成元素个数尽量相等的两半,把两半元素分别排序,两个有序表合并成一个

Loading…
Cancel
Save