冒泡排序练习题

冒泡排序练习题

1.【加试题】有一个数组,采用冒泡排序,第一遍排序后的结果为:4,10,5,32,6,7,9,17,24

那么该数组的原始顺序不可能的是 ...

A.10,5,32,6,7,9,17,24,4 C.10,5,32,4,6,7,9,17,24

2.【加试题】有如下程序段: For i = 1 To 2

For j = 5 To i + 1 Step -1 If a(j) > a(i) Then

t = a(j): a(j) = a(i): a(i) = t End If Next j Next i

数组元素a(1)到a(5)的值依次为“33,24,45,16,77”,经过该程序段“加工”后,数组元素a(1)到a(5)的值依次为

A. 77,45,33,16,24

B. 77,33,45,16,24

C. 77,24,45,16,33

D. 77,45,33,24,16

3.数据“56,23,78,11,8”依次存放在数组a(1)到a(5)中,执行下列VB程序段后,数组a(1)到a(5)中的数据依次为( ) For i = 1 To 2

For j = 1 To 5-i

If a(j+1) < a(j) Then t = a(j): a(j) = a(j+1): a(j+1) = t

Next j Next i

A. 8,11,23,56,78 B. 23,11,8,56,78 C. 11,8,23,56,78 D. 8,11,56,23,78

4.【加试题】有如下Visual Basic程序段:

Dim a(1 To 7) As Integer, i As Integer, j As Integer, k As Integer, c As Integer a(1) = 3: a(2) = 9: a(3) = 1: a(4) = 5: a(5) = 8: a(6) = 6: a(2) = 2 s = \For i = 1 To 3 For j = i + 1 To 7 If a(j) < a(i) Then

k = a(j): a(j) = a(i): a(i) = k c = c + 1 End If Next j s = Str(a(i)) + s Next i

text1.Text = Str(c) & “:” & s 该程序段运行后,文本框Text1中显示的内容是 A.5:6 8 9

B. 3: 9 8 6

C. 3:1 2 3

D.5:3 2 1

B. 10,5,32,6,7,9,4,17,24[来源:学&科& D. 4,10,5,32,17,9,24,6,7

5. 【加试题】有以下VB程序段 For i = 1 To 2 For j = 1 To 5-i If d(j) > d(j +1)Then

t = d(j):d(j) = d(j +1):d(j +1) = t End If Next j Next i

数组元素a(1)到a(5)的值依次为“48,36,78,18,15”,经过该程序段“加工”后,数组元素a(1)到a(5)的值依次为

A.36,15,18,48,78

B.36,18,15,48,78

C.15,18,36,48,78 D.15,18,48,36,78

6.【加试题】有如下程序段: For i = 1 To 2

For j = 2 To 7 - i

If a(j) > a(j - 1) Then

k = a(j): a(j) = a(j - 1): a(j - 1) = k End If Next j

Next i

数组元素a(1)到a(6)的值依次为“71,54,58,29,31,78”,经过该程序段“加工”后,下列说法正确的是( )

A.数组元素a(1)到a(6)的值依次为54,29,31,58,71,78 B.此过程中数据共需比较次数为8次 C.此过程中数据共需交换次数为5次

D.此过程中数据“54”共被比较5次

7.【加试题】有如下 V B 程序段: Dim s(1 To 6) As String Text1.Text = \For i = 1 To 5

For j = i + 1 To 6

If s(i) + s(j) < s(j) + s(i) Then t = s(j): s(j) = s(i): s(i) = t End If Next j Next i

For i = 1 To 6

Text1.Text = Text1.Text + s(i) Next i

如果程序运行,一开始当数组元素s(1)到s(6)的值依次为“4”、“343”、“312”、“12”、“246”、“121”,运行该段代码后,文本框Text1中显示的内容为( )

A.434331224612121 B.434331224612112 C.343312246121124 D.121122463123434

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4