package com.jackie.bubbleSort; import java.util.Arrays; /** * ��ð������ʵ�ֶ� 9 8 7 6 5 ���������� * ˼·������ * ��һ�ˣ�������������ҳ���������9 * ��һ�Σ�8 9 7 6 5 8��9���� * �ڶ��Σ�8 7 9 6 5 7��9���� * ����Σ�8 7 6 9 5 6��9���� * ���ĴΣ�8 7 6 5 9 5��9���� * �ڶ��ˣ�������������ҳ�����8 * ��һ�Σ�7 8 6 5 9 7��8���� * �ڶ��Σ�7 6 8 5 9 6��8���� * ����Σ�7 6 5 8 9 5��8���� * ���ĴΣ�7 6 5 8 9 8��9���������ý���λ�� * �����ˣ�������������ҳ�����7 * ��һ�Σ�6 7 5 8 9 6��7���� * �ڶ��Σ�6 5 7 8 9 5��7���� * ����Σ�6 5 7 8 9 7��8���������ý���λ�� * ���ĴΣ�6 5 7 8 9 7��9���������ý���λ�� * �����ˣ�������������ҳ�����6 * ��һ�Σ�5 6 7 8 9 5��6���� * �ڶ��Σ�5 6 7 8 9 6��7���������ý���λ�� * ����Σ�5 6 7 8 9 6��8���������ý���λ�� * ���ĴΣ�5 6 7 8 9 6��9���������ý���λ�� * * ͨ������ϵķ����Լ�����ִ�н��ɷ��֣��ð汾�Դ��ڿ��Ż��ĵط��� * ���һ��8��9�Ѿ��ȽϹ��ˣ����ǵڶ����ֽ�����һ�αȽϣ���˿ɼ�������ʽ�� * �������ִ�д������˺ܶ� * ��һ�ˣ�������������ҳ���������9 * ��һ�Σ�8 9 7 6 5 8��9���� * �ڶ��Σ�8 7 9 6 5 7��9���� * ����Σ�8 7 6 9 5 6��9���� * ���ĴΣ�8 7 6 5 9 5��9���� * �ڶ��ˣ�������������ҳ�����8 * ��һ�Σ�7 8 6 5 9 7��8���� * �ڶ��Σ�7 6 8 5 9 6��8���� * ����Σ�7 6 5 8 9 5��8���� * �����ˣ�������������ҳ�����7 * ��һ�Σ�6 7 5 8 9 6��7���� * �ڶ��Σ�6 5 7 8 9 5��7���� * �����ˣ�������������ҳ�����6 * ��һ�Σ�5 6 7 8 9 5��6���� * * �Ż����հ汾��������������߾���ij�˺����������� * �磺 8 1 2 3 4 * ��һ�ˣ�1 2 3 4 8 * �ڶ��ˣ�1 2 3 4 8 û�о����κν�����ֹͣ * @author liutao * @date 2017��12��4�� ����4:10:31 */ public class BubbleSort3 { public static void main(String[] args) { int[] arr = {9,8,7,6,5}; arr = new int[]{9,1,2,3,4}; arr = new int[]{8,9,1,2,3,4}; arr = new int[]{1,2,3,9,4}; sort(arr); //sortFinal(arr); } public static void sort(int[] arr){ int temp; int len = arr.length; boolean sorted = true; //ִ������ for(int j = 0;j < len - 1; j ++){ sorted = true;//�ٶ����� //ִ�д��� for(int i = 0;i < len - 1 - j; i ++){ System.out.print("��" + (j + 1) + "�ˣ�"); System.out.print("��" + (i + 1) + "�Σ�"); if(arr[i] > arr[i + 1]){ temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; sorted = false;//�ٶ�ʧ�� } System.out.println(Arrays.toString(arr)); } if(sorted){ break; } } } }

dixiu000 LV4
2023年1月30日
微信网友_6040315240812544 LV8
2022年10月27日
pandahuo
2022年3月6日
暂无贡献等级
智禾信息
2021年12月29日
暂无贡献等级
wangwenzhong LV9
2020年12月28日
kinggode LV14
2020年7月28日
抗着大鸟打飞机 LV5
2020年6月30日
lllpppwww LV5
2020年4月4日
wwwbl123 LV2
2020年3月11日
black8angel LV4
2020年2月23日