澳门下载app送35元彩金大全,下载APP送36元彩金,下载app送8至88彩金

当前位置:首页 > 十堰市澳门下载app送35元彩金大全学校 > 特色教育 > 创客教育

链表的基础应用-取随机数

日期:2020-02-20 20:35:00     

&nbsp;<span style="color: rgb(51, 51, 51); font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; letter-spacing: 0.54px; orphans: 2; text-align: justify; widows: 2; line-height: 1.4; background-color: rgb(254, 255, 255);">之前讲了链表应用,今天在多加一讲针对链表的应用,让大家对链表的概念掌握的更清楚些。</span>
<p>&nbsp;</p>
<p style="text-align: center; color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; overflow-wrap: break-word; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; overflow-wrap: break-word; box-sizing: border-box !important;">———— / 随机数 / ————</span></p>
<p style="color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; overflow-wrap: break-word; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; overflow-wrap: break-word; box-sizing: border-box !important;">scratch里面有随机数的命令,就是在一段数字之间取随机值。</span></p>
<p>&nbsp;</p>
<p><span class="ans-img-wrap" id="ext-gen1038"><img width="208" height="42" title="1.png" id="ext-gen1039" src="./W020200303640260843064.png" alt="" OLDSRC="W020200303640260843064.png" /></span></p>
<p>&nbsp;</p>
<p style="color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; overflow-wrap: break-word; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; letter-spacing: 0.54px; max-width: 100%; box-sizing: border-box !important;">但是我们往往面对的取随机数的时候不是取数字,而是取一些非数字的值,比如说星期几?什么星座?哪种小动物?这些都不是数字,而是一个非数字的组合。那么针对这种情况随机值怎么取?</span>这就要用到链表了。</span></p>
<p style="text-align: center; color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; box-sizing: border-box !important;">———— / 举例 / ————</span></p>
<p style="color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; box-sizing: border-box !important;">我们用一个猜星期几的例子,大家看一下:</span></p>
<p>&nbsp;</p>
<div class="ans-attach-ct"><iframe class="ans-attach-online ans-insertvideo-online" src="https://mooc1-2.chaoxing.com/ananas/modules/video/index.html?v=2019-1113-1705" frameborder="0" scrolling="no" mozallowfullscreen="true" webkitallowfullscreen="true" allowfullscreen="true" data="{&quot;objectid&quot;:&quot;41835a5dbc652f5a88e20c8bbcff4202&quot;,&quot;name&quot;:&quot;QQ\u5f55\u5c4f20200219183130.mp4&quot;,&quot;type&quot;:&quot;.mp4&quot;,&quot;size&quot;:3505276,&quot;hsize&quot;:&quot;3.34 MB&quot;,&quot;mid&quot;:&quot;10186445829031582108314471&quot;,&quot;_jobid&quot;:&quot;1582108314735186&quot;}" mid="10186445829031582108314471" vend="" vbegin="" switchwindow="" fastforward="" objectid="41835a5dbc652f5a88e20c8bbcff4202">
</iframe></div>
&nbsp;
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="text-align: center; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; orphans: 2; widows: 2; font-variant-ligatures: normal;">我们来看一下代码:</span></p>
<p><span class="ans-img-wrap float-none" id="ext-gen1040"><img width="502" height="575" title="2.png" id="ext-gen1041" src="./W020200303640311938941.png" alt="" OLDSRC="W020200303640311938941.png" /></span></p>
<p style="text-align: center; color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; box-sizing: border-box !important;">这是小猫的代码</span></p>
<p style="text-align: justify; color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; box-sizing: border-box !important;"><br style="margin-right: 0px; margin-left: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important;" />
<span class="ans-img-wrap float-none" id="ext-gen1042"><img width="251" height="61" title="3.png" id="ext-gen1043" src="./W020200303640312992803.png" alt="" OLDSRC="W020200303640312992803.png" /></span></p>
<p style="text-align: justify; color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; text-align: center; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; box-sizing: border-box !important;">首先创建了一个星期的链表,在程序开始的部分要注意:首先要进行初始化,把链表清零,因为链表在程序结束后是不会自动清零的,当你在开始运行程序时,链表里的老数据就会干扰程序运行。</span></p>
<p><span class="ans-img-wrap float-none" id="ext-gen1044"><img width="249" height="280" title="4.png" id="ext-gen1045" src="./W020200303640313880880.png" alt="" OLDSRC="W020200303640313880880.png" /></span></p>
<p>&nbsp;</p>
<p><span style="text-align: center; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; orphans: 2; widows: 2; font-variant-ligatures: normal;">然后将星期日到星期六全部加入链表</span></p>
<p><span class="ans-img-wrap float-none" id="ext-gen1046"><img width="513" height="122" title="5.png" id="ext-gen1047" src="./W020200303640314779340.png" alt="" OLDSRC="W020200303640314779340.png" /></span></p>
<p>&nbsp;</p>
<p><span style="text-align: center; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; orphans: 2; widows: 2; font-variant-ligatures: normal;">这段代码是根据当前时间算出今天是星期几。并开始提问</span></p>
<p><span style="margin-right: 0px; margin-left: 0px; padding: 0px; text-align: center; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; max-width: 100%; box-sizing: border-box !important;"><span class="ans-img-wrap float-none" id="ext-gen1048"><img width="257" height="234" title="6.png" id="ext-gen1049" src="./W020200303640315612255.png" alt="" OLDSRC="W020200303640315612255.png" /></span></span></p>
<p>&nbsp;</p>
<p><span style="text-align: center; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; orphans: 2; widows: 2; font-variant-ligatures: normal;">这段重复代码是让小狗反复回答,知道猜到了几天是星期几为止。</span></p>
<p><span class="ans-img-wrap float-none" id="ext-gen1050"><img width="359" height="189" title="7.png" id="ext-gen1051" src="./W020200303640316488478.png" alt="" OLDSRC="W020200303640316488478.png" /></span></p>
<p><span style="text-align: center; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; orphans: 2; widows: 2; font-variant-ligatures: normal;">小狗的代码很简单,首先在1~7中间取一个随机数,然后再将链表中对应的第几项中的文字提取出来。就表明猜得是星期几。这就是非整数的一组数据如何取随机数的办法。</span></p>
<p>&nbsp;</p>
<p style="text-align: center; color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; box-sizing: border-box !important;">———— / 取不重复的随机数 / ————</span></p>
<p style="color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; text-align: center; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; box-sizing: border-box !important;">但是刚才的程序里有明细不合理的地方,就是小狗太笨了,明明错误的答案,下次还会再说一遍,为什么呢?是因为我们取随机数的时候并没有限定不能重复,所以每次取的时候自然有可能跟以前的数字重复了。那怎么做的呢?</span></p>
<p><span style="text-align: center; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; orphans: 2; widows: 2; font-variant-ligatures: normal;">把之前取的数字都记录下来,每次取的新数字先拿来跟之前取过的数字一一比较,如果发现重复,那么放弃掉这次取的数字,然后重新选取。(这种的代码就留给同学们自己练习吧)</span></p>
<p style="text-align: center; color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; overflow-wrap: break-word; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; overflow-wrap: break-word; box-sizing: border-box !important;"><br class="Apple-interchange-newline" />
———— / 总结</span><span style="margin-right: 0px; margin-left: 0px; padding: 0px; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; overflow-wrap: break-word; box-sizing: border-box !important;">&nbsp;/ ————</span></p>
<p style="text-align: justify; color: rgb(51, 51, 51); letter-spacing: 0.54px; clear: both; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; min-height: 1em; max-width: 100%; orphans: 2; widows: 2; font-variant-ligatures: normal; overflow-wrap: break-word; box-sizing: border-box !important;"><span style="margin-right: 0px; margin-left: 0px; padding: 0px; text-align: center; color: rgb(63, 63, 63); letter-spacing: 0.54px; font-family: 'PingFang SC', 'Source Sans Pro', 'Hiragino Sans GB', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', arial, sans-serif; font-size: 14px; max-width: 100%; overflow-wrap: break-word; box-sizing: border-box !important;">今天的内容比较简单,但是很实用,在游戏编程中也经常用到,以后碰到非数字的数据组取不重复的随机值,都可以用这种算法。</span></p>

主办单位:十堰市澳门下载app送35元彩金大全学校 版权所有:十堰市澳门下载app送35元彩金大全学校

鄂ICP备06007886号-5 鄂公网安备 42030202000140号 技术支持:十堰政府网

学校地址:十堰市张湾区云南路22号

联系电话:0719-澳门下载app送35元彩金大全,下载APP送36元彩金,下载app送8至88彩金