资源简介 (共11张PPT)e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B7247高中信息技术数据排序—冒泡排序e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B7247冒泡排序目录01课前回顾02代码实现03习题演练04课堂总结e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B7247课前回顾上节课学了什么?1、冒泡排序的定义从前到后(即从下标较小的元素开始)依次比较相邻元素的值,若发现逆序则交换位置,使值较大的元素逐渐从前移向后部。2、冒泡排序的过程从小到大排序一、、e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B7247第一次排序7>3逆序,交换位置7<22正序,保持不变同之前规律第一次排完第二次排完第一轮排序以后,最大的数就会浮到最右面;第二轮排序时,只排到导数第二个...以此排完。重点理解:第二次排序e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B7247下面关于冒泡排序说法正确的是()练一练A、只能从小到大排序B、可以一次比较三个以上的元素C、当比较的两个数逆序时,交换顺序D、只能比较数据√e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B7247for i in range(len(list)-1):for j in range(len(list) - i - 1):if list[j] > list[j + 1]:list[j],list[j+1] = list[j+1],list[j]二、代码实现3, 7, 15, 8, 223, 7, 8, 15, 22i∈[0,n-1),大循环j∈[0,n-i-1),小循环将当前指向的数和后一个数相比较较大的后移一位如果if后的表达式为真则执行if里的程序,否则,不执行,直接进入下一循环。3, 7, 8, 15, 223, 7, 8, 15, 22e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B7247if list[j-1] > list[j]:list[j-1],list[j] = list[j],list[j-1]从小到大排序,先确定最小。if list[j] > list[j + 1]:list[j],list[j+1] = list[j+1],list[j]j = nj = 1从小到大排序,先确定最大。“<”改为”>”则变为从大到小排序“>”改为”<”则变为从大到小排序e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B7247range函数:range(start, stop[, step])start: 计数从 start 开始。默认是从 0 开始。stop: 计数到 stop 结束,但不包括 stop。step:步长,默认为1。三、习题演练1. 有如下 python 程序段:n=6a = []for i in range(3):for j in range(n - i - 1):if a[j]>a[j+1]:a[j],a[j+1]=a[j+1],a[j]print(a)数组元素a(1)到a(6)的数据依次为“50,31,18,42,37,23”,则此程序运行完成后数组元素的数据依次是( )A 50,42,37,31,23,18 B 18,23,31,50,37,42C 18,31,23,37,42,50 D 18,23,31,37,42,50√e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B724750,31,18,42,37,23If a(j)>a(j+1)从小到大排序,现在确定最大排除A解题步骤一解题步骤二31,18,42,37,23,5018,31,37,23,42, 5018,31,23,37,42, 50i = 1i = 2i = 3e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B7247四、课堂总结01什么是冒泡排序02代码实现03课后习题,完成课本上的练习。从前到后(即从下标较小的元素开始)依次比较相邻元素的值,若发现逆序则交换位置,使值较大的元素逐渐从前移向后部。e7d195523061f1c0f0ec610a92cff745ee13794c7b8d98f8E73673273C9E8BE17CC3D63B9B1D6426C348A354AD505654C28F453CD7C8F90EADD06C08281DAED7140E5AAAED5880ECE414DFB6A93B82BE019406867034C3A8500A4827DCF3FBF74A471B736410707E336A01C9ADC9BE02ACCB8DF2121D81636A067B8AE80C6AB6F014154F4E7B7247谢 谢 展开更多...... 收起↑ 资源预览