两个数 据 应是 34 对 25 5 把内循 环执行

Info icon This preview shows pages 10–12. Sign up to view the full content.

View Full Document Right Arrow Icon
两个数 ( 应是 34 25) 5 、把内循 环执行 ,检查 成第一 趟扫 后是否 已把最 大值 6 15 行,检查数 是否 已排 启动 调试 执行到下一 位置 检查 前值 前值正确 找到 问题 所在 Y N
Image of page 10

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
11 江汉大学数学与计算机科学学院 韩海 江汉大学数学与计算机科学学院 韩海 13971189810 13971189810 补充 冒泡排 序法 34 25 78 63 21 18 43 66 58 49 冒泡排 序法: (1) 每一 趟扫描从左 向右 次检查每一对相 邻元素 (2) 如果相 邻元素 不符合 序要求则 交换 ,否则不 (3) 成一 趟扫描 后, 元素 一定 交换 位置 (4) 二趟扫描 只需要对前面 N-1 元素 进行 (5) 进行 N-1 趟扫描 后,所有 元素均已排好 34 25 78 63 21 18 43 66 58 49 1 对相 34 25 2 对相 3 对相 78 63 4 对相 78 21 5 对相 78 18 6 对相 78 43 7 对相 78 66 8 对相 78 58 9 对相 78 49 78 二趟扫描 只对前 9 元素 进行
Image of page 11
12 江汉大学数学与计算机科学学院 韩海 江汉大学数学与计算机科学学院 韩海 13971189810 13971189810 EX8-2.C #include <stdio.h> #define N 10 main( ) { int data [N] ,i, j , k ; printf( " \n\n I nput %d numbers : \n " , N ); for(i=1;i<= N ;i++) scanf( " %d " ,data [ i ] ); for(i=1;i< N ;i++) / * 在此检查 data 数 中的值 * / for( j =i+1; j <= N ; j ++) if(data [j] >data [j +1 ] ) / * 在此检查 j 的值,第一次 比较 * / { k =data [j] ; / * 在此检查 j 的值,第一次 交换 * / data [j] =data [j +1 ] ; data [j +1 ] = k ; } / * i 由 1 2 时检查 大数是否 * / printf( " \n\n S orted numbers : \n " ); for(i=1;i<= N ;i++) printf( " %5d " ,data [ i ] ); }
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern