資源簡(jiǎn)介 專項(xiàng)測(cè)試五 排序算法一、選擇題1.采用冒泡排序算法對(duì)數(shù)組a中的6個(gè)數(shù)據(jù)“8,20,5,17,30,9”進(jìn)行排序,部分程序代碼如下:For i=1 To 2 For j=6 To i+1 Step -1If a(j)>a(j-1) Then t=a(j): a(j)=a(j-1): a(j-1)=t End If Next jNext i運(yùn)行該程序,數(shù)據(jù)交換的次數(shù)為( )A.1 B.2 C.3 D.4解析 本題主要考查的是冒泡排序的數(shù)據(jù)交換次數(shù)。根據(jù)語(yǔ)句“If a(j)>a(j-1)Then”可知,排序方式為從大到小排序(降序),排序是通過(guò)從后往前相鄰數(shù)據(jù)比較和交換進(jìn)行,排序過(guò)程如下:原始數(shù)據(jù)820517309說(shuō)明第1趟30820517930分別與17、5、20、8交換位置,因此,共交換4次第2趟30208175917與5交換位置,20與8交換位置,因此,共交換2次因此,答案為B。答案 B2.采用冒泡排序?qū)?shù)組d中元素進(jìn)行排序,第一趟排序后的結(jié)果為“10,25,15,30,50,38,60,55”,則d數(shù)組中元素的初始順序不可能是( )A.25,15,30,50,38,60,55,10B.25,15,30,50,38,60,10,55C.25,15,10,50,38,60,30,55D.25,15,30,50,10,38,60,55解析 觀察第一趟的排序可知,數(shù)據(jù)是按升序排序的,數(shù)據(jù)比較和交換是從后往前進(jìn)行的,本題可從選項(xiàng)模擬排序,D選項(xiàng)進(jìn)行第一趟排序后的數(shù)據(jù)順序?yàn)椤?0,25,15,30,50,38,55,60”,因此,答案為D。答案 D3.對(duì)數(shù)組元素b(1)~b(8)進(jìn)行降序排序,其排序算法的VB部分程序如下:For x = 1 To 7 w = x For y = x + 1 To 8 Next y If w < > x Then Temp = b(x): b(i) = b(w): b(w) = temp End IfNext x方框中應(yīng)填入的語(yǔ)句為( )A.If b(w) > b(y) Then w = yB.If b(w) < b(y) Then w = yC.If b(w) > b(y) Then w = xD.If b(w) < b(y) Then w = x解析 本題主要考查的是選擇排序算法的程序?qū)崿F(xiàn)。排序方式為降序,用變量w記錄當(dāng)前最大的元素所在的位置,當(dāng)在后面找到更多的數(shù)時(shí),則更新w的值,因此加框處的代碼為If b(w) < b(y) Then w = y,答案為B。答案 B4.有如下程序段:For i = 1 To 4For j = i + 1 To 5 If a(j) > a(i) Then t = a(j): a(j) = a(i): a(i) = tNext jNext i數(shù)組元素a(1)~a(5)的值依次為“15,4,12,7,9”,整個(gè)排序過(guò)程中,數(shù)組中數(shù)據(jù)比較次數(shù)和交換次數(shù)分別是( )A.比較11次,交換3次B.比較11次,交換4次C.比較10次,交換3次D.比較10次,交換4次解析 本題主要考查的是選擇排序算法。這是非優(yōu)化的選擇排序,每遍排序時(shí)將i位置的元素順序與它后面的元素比較,若比它大,則交換它們的位置。排序過(guò)程如下表所示:原始數(shù)據(jù)1541279比較次數(shù)和交換次數(shù)第一趟結(jié)束時(shí)1541279比較4次,無(wú)交換第二趟1512479比較3次,交換1次第三趟1512947比較2次,交換2次第四趟1512974比較1次,交換1次因此,共比較次數(shù)為4+3+2+1=10次,共交換次數(shù)為1+2+1=4次,答案為D。答案 D5.如下VB程序段:st = “ ”For i = 1 To 4 For j = 1 To 10 - iIf d(j) < d(j + 1) Then temp = d(j): d(j) = d(j + 1): d(j + 1) = tempEnd If Next j st = Str(d(j)) + stNext iText1.Text = st數(shù)組元素d(1)~d(10)中的數(shù)據(jù)依次為“21,8,12,16,26,71,65,89,42,36”,程序執(zhí)行后,在文本框Text1中顯示的內(nèi)容是( )A.8,12,16,21 B. 42,65,71,89C.21,16,12,8 D.89,71,65,42解析 本題考查的是冒泡排序算法的程序?qū)崿F(xiàn)。該程序的功能是對(duì)數(shù)據(jù)使用冒泡排序降序排序4趟,并將每趟得到的最小值存放在字符串st中,需注意的是語(yǔ)句st = Str(d(j)) + st,即將當(dāng)前得到的最小數(shù)拼接在字符串st的前面。因此,四趟排序結(jié)束后,變量st的值為“21,16,12,8”,答案為C。答案 C6.有如下VB程序段:Private Sub Command1_Click() Dim a(1 To 100) As String, x As String, st As String Dim i As Integer, j As Integer, n As Integer x = Text1.Text n = Len(Text1.Text) For i = 1 To na(i) = Mid(x, i, 1) Next i For i = 1 To n - 1For j = n To i + 1 Step -1 If a(j) > a(j - 1) Thenst = a(j): a(j) = a(j - 1): a(j - 1) = st End IfNext j Next i st = “ ” For i = 1 To nst = st + a(i) Next i Label1.Caption = stEnd Sub程序運(yùn)行時(shí),在文本框Text1中輸入“Text”(不包含雙引號(hào)),單擊按鈕Command1,則在標(biāo)簽Label1上顯示的內(nèi)容為( )A.Tetx B.Txte C.xtTe D.xteT解析 本題主要考查的是冒泡排序算法。本題的功能是將文本框中輸入的字符串進(jìn)行降序排序,字符比較大小實(shí)質(zhì)是比較字符的ASCII碼,小寫(xiě)字母的ASCII值大于大寫(xiě)字母,因此排序結(jié)果為xteT,答案為D。答案 D二、非選擇題7.下面是一個(gè)采用拉鋸式排序法對(duì)數(shù)組元素按升序進(jìn)行排序的程序,所謂“拉鋸式排序法”是這一遍把最小的元素從下往上移動(dòng)到最上面的位置,下一遍則是從上往下把最大的元素移動(dòng)到最下面的位置。 程序運(yùn)行效果如下圖所示。Private Sub Command1_Click() Dim a(10) As Integer, i As Integer Randomize ′產(chǎn)生不同的隨機(jī)數(shù) For i = 1 To 10a(i) = Int(Rnd * 100) + 1Text1.Text = Text1.Text & Str(a(i)) Next i Call Shaker_sort(a()) ′調(diào)用Shaker_sort For i = 1 To 10Text2.Text = Text2.Text & Str(a(i)) Next iEnd SubPrivate Sub Shaker_sort(k() As Integer) Dim i As Integer,c As Integer,d As Integer Dim t As Integer c = 1 d = 10 Do While c<=d For i=______①______ ′從下往上把最小的元素移到最上面的位置 If k(i-1)>k(i) Then t = k(i - 1):k(i- 1) = k(i):k(i) = t End If Next i For i = c+1 To d-c ′從上到下把最大的元素移到最下面的位置 If ______②______ Then t = k(i+1):k(i+1) = k(i):k(i) = t End If Next i c = c + 1 ______③______ Loop End Sub解析 此題考查排序算法的分析和拓展。①代碼表示把當(dāng)前最小的元素從下往上移到最上面的位置,因此代碼為d to c+1 Step -1;②處所在循環(huán)的功能是從上到下把最大的元素移到最下面的位置,即當(dāng)前位置的元素比后面元素大時(shí),交換他們的位置,因此②處代碼為k(i)>k(i+1);每一趟排序?qū)⑴哦^尾兩個(gè)數(shù)的位置,因此,③處代碼為 d=d-1。答案 ①d to c+1 Step -1 ②k(i)>k(i+1)③d=d-18.小李基于冒泡排序算法編寫(xiě)了一個(gè)VB程序,功能如下:在文本框Text1中顯示排序前的數(shù)據(jù),單擊“排序”按鈕Command1,在文本框Text2中顯示剔除重復(fù)數(shù)據(jù)后的升序排序結(jié)果。程序運(yùn)行界面如下圖所示。實(shí)現(xiàn)上述功能的VB程序如下,但加框處代碼有錯(cuò),請(qǐng)改正。Const n = 10Dim a(1 To n) As IntegerPrivate Sub Command1_Click() Dim i As Integer, j As Integer, t As Integer,bottom As Integer ′獲取排序前數(shù)據(jù)依次存儲(chǔ)在數(shù)組a中,并在文本框Text1中顯示。代碼略 bottom = n i = 1 Do While i <= bottom - 1For j = bottom To i + 1 Step -1 If Then ′①t = a(j): a(j) = a(j - 1): a(j - 1) = t ElseIf a(j) = a(j - 1) Then ′相鄰兩個(gè)數(shù)據(jù)相等,進(jìn)行剔除處理 ′②bottom = bottom - 1 End IfNext ji = i + 1LoopText2.Text = “ ”For i = 1 To bottom Text2.Text = Text2.Text + Str(a(i))Next iEnd Sub程序中加框①處應(yīng)改正為_(kāi)________________________________________;加框②處應(yīng)改正為_(kāi)______________________________________________。解析 本題考查的是冒泡排序算法的變式。從數(shù)據(jù)交換的語(yǔ)句可知,加框①處的表達(dá)式為a(j)與a(j-1)的比較,因?yàn)榕判蚍绞綖樯颍虼思涌颌偬幍拇a修改為a(j)答案 ①a(j) a(j)②a(j)=a(bottom)或t=a(j):a(j)=a(bottom):a(bottom)=t9.編寫(xiě)一個(gè)VB程序,實(shí)現(xiàn)功能為在n個(gè)數(shù)中尋找第m大的數(shù)。程序運(yùn)行時(shí),自動(dòng)生成n個(gè)三位數(shù)隨機(jī)整數(shù),并顯示在列表框List1中,單擊“排序”按鈕Command1,將數(shù)據(jù)進(jìn)行排序,并將排好序的數(shù)據(jù)顯示在列表框List2中,在文本框Text1中輸入m,單擊“計(jì)算”按鈕Command2,在文本框Text2中顯示第m大的數(shù)。程序運(yùn)行效果如下圖所示:為實(shí)現(xiàn)上述功能的VB程序如下,在程序劃線處填入合適的代碼。Dim d(1 To 20) As IntegerConst n = 20Private Sub Form_Load() Dim i As Integer, j As Integer, t As Single List1.Clear Randomize For i = 1 To n ________①________ List1.AddItem Str(d(i)) Next iEnd SubPrivate Sub Command1_Click() Dim i As Integer, j As Integer, t1 As Integer For i = 1 To n - 1 For j =________②________ If d(j) < d(j - 1) Then t1 = d(j): d(j) = d(j - 1): d(j - 1) = t1 End If Next j Next i For i = 1 To n List2.AddItem Str(d(i)) Next iEnd SubPrivate Sub Command2_Click() Dim m As Integer m = Val(Text1.Text) Text2.Text = “第” + Str(m) + “ 大的數(shù)為:” + ________③________End Sub解析 本題采用冒泡排序算法。①處主要考查的是隨機(jī)函數(shù),要求生成三位數(shù)整數(shù)(即[100,999]范圍內(nèi)的整數(shù)),根據(jù)代碼“List1.AddItem Str(d(i))”可知,隨機(jī)數(shù)存儲(chǔ)在數(shù)組d中,第i個(gè)隨機(jī)數(shù)存儲(chǔ)在數(shù)組元素d(i)中,因此,①處代碼為d(i)=Int((Rnd * 900+100));②處所在的事件處理過(guò)程是冒泡排序,從交換語(yǔ)句可知,相鄰數(shù)據(jù)的比較是從后往前進(jìn)行的,因此②處代碼為n To i + 1 Step -1;③處代碼考查的是學(xué)生的思維能力,由于排序后的數(shù)據(jù)是升序,因此第m大的數(shù)為d(n-m+1),而不是d(n-m),因此③處代碼為Str(d(n - m + 1))。答案 ①d(i) = Int((Rnd * 900 + 100))②n To i + 1 Step -1 ③Str(d(n - m + 1))10.小王編寫(xiě)了一個(gè)數(shù)據(jù)排序且將重復(fù)數(shù)刪除的VB程序。算法的基本思想:先隨機(jī)生成20個(gè)[1,50]區(qū)間內(nèi)的整數(shù),然后按照數(shù)據(jù)從低到高進(jìn)行排序,最后刪除重復(fù)數(shù)(相同的數(shù)據(jù)只保留一個(gè))。程序運(yùn)行時(shí),單擊“生成隨機(jī)數(shù)”按鈕Command1,則生成20個(gè)[1,50]區(qū)間內(nèi)的整數(shù),存儲(chǔ)在數(shù)組a中,并顯示在文本框Text1中;單擊“排序并去重”按鈕Command2,則將數(shù)組a中數(shù)據(jù)進(jìn)行從低到高排序,并將排序結(jié)果顯示在文本框Text2中,將去重后結(jié)果顯示在文本框Text3中,在標(biāo)簽Label4中顯示共刪除的重復(fù)數(shù)個(gè)數(shù),程序運(yùn)行界面如下圖所示。實(shí)現(xiàn)上述功能的VB程序如下,請(qǐng)回答下列問(wèn)題:(1)若20個(gè)隨機(jī)數(shù)分別為:7,18,5,7,7,12,7,1,10,14,17,7,9,7,10,16,5,18,8,18,則去掉的重復(fù)數(shù)共________個(gè)。(2)請(qǐng)?jiān)趧澗€處填入合適的代碼。Dim a(1 To 20) As IntegerConst n = 20Private Sub Command1_Click() Dim i As Integer, s1 As String Randomize s1 = “ ” For i = 1 To na(i) = Int(Rnd * 50 + 1)s1 = s1 + Str(a(i)) Next i Text1.Text = s1End SubPrivate Sub Command2_Click() Dim i As Integer, j As Integer, p As Integer, tt As Integer Dim ans As Integer, s2 As String, s3 As String For i = 1 To n - 1p = iFor j = n To i + 1 Step -1 If a(j) < a(p) Then p = jNext jIf a(i) < > a(p) Then tt = a(i) a(i) = a(p) a(p) = ttEnd If Next i s2 = “ ”:s3 = “ ” ans = 0 For i = 1 To n s2 = s2 + Str(a(i)) Next i Text2.Text = s2 __________①__________ s3 = Str(a(1)) For i = 2 To nIf a(i) < > q Then __________②__________ q = a(i)Else __________③__________End If Next i Text3.Text = s3 Label4.Caption = Str(ans)End Sub解析 (1)重復(fù)的數(shù)有5、7、10、18,去掉1個(gè)5,5個(gè)7,1個(gè)10,2個(gè)18,因此共刪除的重復(fù)數(shù)有9個(gè)。(2)本題的算法思想是:首先將數(shù)據(jù)進(jìn)行升序排序,然后將相鄰的重復(fù)數(shù)刪除。因此,先將第一個(gè)數(shù)賦給變量q,然后從2個(gè)數(shù)開(kāi)始與q進(jìn)行比較,如果不相等,說(shuō)明當(dāng)前的數(shù)與它前面的數(shù)不重復(fù),則將它存放在字符串s3中,并把當(dāng)前數(shù)賦給q,繼續(xù)往下比較;如果相等,說(shuō)明當(dāng)前的數(shù)與它前面的數(shù)重復(fù),則不放入字符串s3,進(jìn)行重復(fù)數(shù)的計(jì)數(shù),根據(jù)語(yǔ)句“Label4.Caption = Str(ans)”可知,重復(fù)數(shù)的個(gè)數(shù)記錄在變量ans中,然后繼續(xù)往下比較。因此①處應(yīng)填入的語(yǔ)句為q=a(1),②處應(yīng)填入的語(yǔ)句為s3=s3+Str(a(i)),③處應(yīng)填入的語(yǔ)句為ans=ans+1。答案 (1)9 (2)①q = a(1)②s3 = s3 + Str(a(i)) ③ans = ans + 1專項(xiàng)測(cè)試五 排序算法一、選擇題1.采用冒泡排序算法對(duì)數(shù)組a中的6個(gè)數(shù)據(jù)“8,20,5,17,30,9”進(jìn)行排序,部分程序代碼如下:For i=1 To 2 For j=6 To i+1 Step -1If a(j)>a(j-1) Then t=a(j): a(j)=a(j-1): a(j-1)=t End If Next jNext i運(yùn)行該程序,數(shù)據(jù)交換的次數(shù)為( )A.1 B.2 C.3 D.42.采用冒泡排序?qū)?shù)組d中元素進(jìn)行排序,第一趟排序后的結(jié)果為“10,25,15,30,50,38,60,55”,則d數(shù)組中元素的初始順序不可能是( )A.25,15,30,50,38,60,55,10B.25,15,30,50,38,60,10,55C.25,15,10,50,38,60,30,55D.25,15,30,50,10,38,60,553.對(duì)數(shù)組元素b(1)~b(8)進(jìn)行降序排序,其排序算法的VB部分程序如下:For x = 1 To 7 w = x For y = x + 1 To 8 Next y If w < > x Then Temp = b(x): b(i) = b(w): b(w) = temp End IfNext x方框中應(yīng)填入的語(yǔ)句為( )A.If b(w) > b(y) Then w = yB.If b(w) < b(y) Then w = yC.If b(w) > b(y) Then w = xD.If b(w) < b(y) Then w = x4.有如下程序段:For i = 1 To 4For j = i + 1 To 5 If a(j) > a(i) Then t = a(j): a(j) = a(i): a(i) = tNext jNext i數(shù)組元素a(1)~a(5)的值依次為“15,4,12,7,9”,整個(gè)排序過(guò)程中,數(shù)組中數(shù)據(jù)比較次數(shù)和交換次數(shù)分別是( )A.比較11次,交換3次B.比較11次,交換4次C.比較10次,交換3次D.比較10次,交換4次5.如下VB程序段:st = “ ”For i = 1 To 4 For j = 1 To 10 - iIf d(j) < d(j + 1) Then temp = d(j): d(j) = d(j + 1): d(j + 1) = tempEnd If Next j st = Str(d(j)) + stNext iText1.Text = st數(shù)組元素d(1)~d(10)中的數(shù)據(jù)依次為“21,8,12,16,26,71,65,89,42,36”,程序執(zhí)行后,在文本框Text1中顯示的內(nèi)容是( )A.8,12,16,21 B. 42,65,71,89C.21,16,12,8 D.89,71,65,426.有如下VB程序段:Private Sub Command1_Click() Dim a(1 To 100) As String, x As String, st As String Dim i As Integer, j As Integer, n As Integer x = Text1.Text n = Len(Text1.Text) For i = 1 To na(i) = Mid(x, i, 1) Next i For i = 1 To n - 1For j = n To i + 1 Step -1 If a(j) > a(j - 1) Thenst = a(j): a(j) = a(j - 1): a(j - 1) = st End IfNext j Next i st = “ ” For i = 1 To nst = st + a(i) Next i Label1.Caption = stEnd Sub程序運(yùn)行時(shí),在文本框Text1中輸入“Text”(不包含雙引號(hào)),單擊按鈕Command1,則在標(biāo)簽Label1上顯示的內(nèi)容為( )A.Tetx B.Txte C.xtTe D.xteT二、非選擇題7.下面是一個(gè)采用拉鋸式排序法對(duì)數(shù)組元素按升序進(jìn)行排序的程序,所謂“拉鋸式排序法”是這一遍把最小的元素從下往上移動(dòng)到最上面的位置,下一遍則是從上往下把最大的元素移動(dòng)到最下面的位置。 程序運(yùn)行效果如下圖所示。Private Sub Command1_Click() Dim a(10) As Integer, i As Integer Randomize ′產(chǎn)生不同的隨機(jī)數(shù) For i = 1 To 10a(i) = Int(Rnd * 100) + 1Text1.Text = Text1.Text & Str(a(i)) Next i Call Shaker_sort(a()) ′調(diào)用Shaker_sort For i = 1 To 10Text2.Text = Text2.Text & Str(a(i)) Next iEnd SubPrivate Sub Shaker_sort(k() As Integer) Dim i As Integer,c As Integer,d As Integer Dim t As Integer c = 1 d = 10 Do While c<=d For i=______①______ ′從下往上把最小的元素移到最上面的位置 If k(i-1)>k(i) Then t = k(i - 1):k(i- 1) = k(i):k(i) = t End If Next i For i = c+1 To d-c ′從上到下把最大的元素移到最下面的位置 If ______②______ Then t = k(i+1):k(i+1) = k(i):k(i) = t End If Next i c = c + 1 ______③______ Loop End Sub8.小李基于冒泡排序算法編寫(xiě)了一個(gè)VB程序,功能如下:在文本框Text1中顯示排序前的數(shù)據(jù),單擊“排序”按鈕Command1,在文本框Text2中顯示剔除重復(fù)數(shù)據(jù)后的升序排序結(jié)果。程序運(yùn)行界面如下圖所示。實(shí)現(xiàn)上述功能的VB程序如下,但加框處代碼有錯(cuò),請(qǐng)改正。Const n = 10Dim a(1 To n) As IntegerPrivate Sub Command1_Click() Dim i As Integer, j As Integer, t As Integer,bottom As Integer ′獲取排序前數(shù)據(jù)依次存儲(chǔ)在數(shù)組a中,并在文本框Text1中顯示。代碼略 bottom = n i = 1 Do While i <= bottom - 1For j = bottom To i + 1 Step -1 If Then ′①t = a(j): a(j) = a(j - 1): a(j - 1) = t ElseIf a(j) = a(j - 1) Then ′相鄰兩個(gè)數(shù)據(jù)相等,進(jìn)行剔除處理 ′②bottom = bottom - 1 End IfNext ji = i + 1LoopText2.Text = “ ”For i = 1 To bottom Text2.Text = Text2.Text + Str(a(i))Next iEnd Sub程序中加框①處應(yīng)改正為_(kāi)________________________________________;加框②處應(yīng)改正為_(kāi)______________________________________________。9.編寫(xiě)一個(gè)VB程序,實(shí)現(xiàn)功能為在n個(gè)數(shù)中尋找第m大的數(shù)。程序運(yùn)行時(shí),自動(dòng)生成n個(gè)三位數(shù)隨機(jī)整數(shù),并顯示在列表框List1中,單擊“排序”按鈕Command1,將數(shù)據(jù)進(jìn)行排序,并將排好序的數(shù)據(jù)顯示在列表框List2中,在文本框Text1中輸入m,單擊“計(jì)算”按鈕Command2,在文本框Text2中顯示第m大的數(shù)。程序運(yùn)行效果如下圖所示:為實(shí)現(xiàn)上述功能的VB程序如下,在程序劃線處填入合適的代碼。Dim d(1 To 20) As IntegerConst n = 20Private Sub Form_Load() Dim i As Integer, j As Integer, t As Single List1.Clear Randomize For i = 1 To n ________①________ List1.AddItem Str(d(i)) Next iEnd SubPrivate Sub Command1_Click() Dim i As Integer, j As Integer, t1 As Integer For i = 1 To n - 1 For j =________②________ If d(j) < d(j - 1) Then t1 = d(j): d(j) = d(j - 1): d(j - 1) = t1 End If Next j Next i For i = 1 To n List2.AddItem Str(d(i)) Next iEnd SubPrivate Sub Command2_Click() Dim m As Integer m = Val(Text1.Text) Text2.Text = “第” + Str(m) + “ 大的數(shù)為:” + ________③________End Sub10.小王編寫(xiě)了一個(gè)數(shù)據(jù)排序且將重復(fù)數(shù)刪除的VB程序。算法的基本思想:先隨機(jī)生成20個(gè)[1,50]區(qū)間內(nèi)的整數(shù),然后按照數(shù)據(jù)從低到高進(jìn)行排序,最后刪除重復(fù)數(shù)(相同的數(shù)據(jù)只保留一個(gè))。程序運(yùn)行時(shí),單擊“生成隨機(jī)數(shù)”按鈕Command1,則生成20個(gè)[1,50]區(qū)間內(nèi)的整數(shù),存儲(chǔ)在數(shù)組a中,并顯示在文本框Text1中;單擊“排序并去重”按鈕Command2,則將數(shù)組a中數(shù)據(jù)進(jìn)行從低到高排序,并將排序結(jié)果顯示在文本框Text2中,將去重后結(jié)果顯示在文本框Text3中,在標(biāo)簽Label4中顯示共刪除的重復(fù)數(shù)個(gè)數(shù),程序運(yùn)行界面如下圖所示。實(shí)現(xiàn)上述功能的VB程序如下,請(qǐng)回答下列問(wèn)題:(1)若20個(gè)隨機(jī)數(shù)分別為:7,18,5,7,7,12,7,1,10,14,17,7,9,7,10,16,5,18,8,18,則去掉的重復(fù)數(shù)共________個(gè)。(2)請(qǐng)?jiān)趧澗€處填入合適的代碼。Dim a(1 To 20) As IntegerConst n = 20Private Sub Command1_Click() Dim i As Integer, s1 As String Randomize s1 = “ ” For i = 1 To na(i) = Int(Rnd * 50 + 1)s1 = s1 + Str(a(i)) Next i Text1.Text = s1End SubPrivate Sub Command2_Click() Dim i As Integer, j As Integer, p As Integer, tt As Integer Dim ans As Integer, s2 As String, s3 As String For i = 1 To n - 1p = iFor j = n To i + 1 Step -1 If a(j) < a(p) Then p = jNext jIf a(i) < > a(p) Then tt = a(i) a(i) = a(p) a(p) = ttEnd If Next i s2 = “ ”:s3 = “ ” ans = 0 For i = 1 To n s2 = s2 + Str(a(i)) Next i Text2.Text = s2 __________①__________ s3 = Str(a(1)) For i = 2 To nIf a(i) < > q Then __________②__________ q = a(i)Else __________③__________End If Next i Text3.Text = s3 Label4.Caption = Str(ans)End Sub 展開(kāi)更多...... 收起↑ 資源列表 專項(xiàng)測(cè)試五 排序算法.doc 專項(xiàng)測(cè)試五 排序算法原卷版.doc 縮略圖、資源來(lái)源于二一教育資源庫(kù)