冒泡算法笔记随笔

冒泡排序

/**
 * ClassName:BubbleSort
 *
 * @author: zhengkw
 * @description: 冒泡排序
 * @date: 20/02/01下午 7:22
 * version: 1.0
 * @since: jdk 1.8
 */
public class BubbleSort {

    public int[] BubbleSort(int[] bubble) {
        int temp = 0;
        for (int i = 0; i < bubble.length; i++) {
            for (int j = 0; j < bubble.length - 1 - i; j++) {
                if (bubble[j] > bubble[j + 1]) {
                    temp = bubble[j];
                    bubble[j] = bubble[j + 1];
                    bubble[j + 1] = temp;
                }
            }

        }

        return bubble;
    }

}




import org.junit.Test;
import static java.lang.System.out;

/**
 * ClassName:Maintest
 *
 * @author: zhengkw
 * // * @description: 测试
 * @date: 20/02/01下午 7:34
 * version:
 * @since: jdk 1.8
 */
public class Maintest {
    @Test
    public void BubbleSortTest1() {

        int[] test = new int[]{51, 54, 1, 0, -25, 59, 78, 88, 67};
        BubbleSort bubbleSort = new BubbleSort();
        test = bubbleSort.BubbleSort(test);

        out.println(test.length);
        for (int a : test
        ) {
            out.print(a+"\t");

        }
    }
}
发布了6 篇原创文章 · 获赞 1 · 访问量 156

猜你喜欢

转载自blog.csdn.net/qq_37714755/article/details/104139248