欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  Java

选择、冒泡排序,二分查找法的用法详解

程序员文章站 2022-04-23 18:45:55
...
   [] array = { 31, 22, 15, 77, 52, 32, 18, 25, 16, 7 ( j = 0; j < array.length; j++ ( i = 0; i < array.length - 1 - j; i++ (array[i] < array[i + 1 temp == array[i + 1+ 1] =
import java.util.Arrays;//选择排序public class Test {public static void main(String[] args) {int[] array = { 31, 22, 15, 77, 52, 32, 18, 25, 16, 7 };// 选择 --> 第一位与后面所有的数字进行比较         System.out.println(Arrays.toString(array));for (int i = 0; i < array.length; i++) {for (int j = i + 1; j < array.length; j++) {if (array[i] < array[j]) {// 如果 array[0]比array[1]大,交换位置// 第三方变量tempint temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(array));
    }
}

   [] array = { 3, 10, 15, 22, 33, 51, 77, 88= "输入需要插入的数据:" number = left = 0 right = array.length - 1 result =[] newArray =  [array.length + 1 ( i = 0; i < newArray.length; i++ (i <=  (i ==== array[i - 1= (   recursion([] array,  left,  right,  (array[0] > 0  (array[array.length - 1] < center = (left + right) / 2 (left == right - 1 (array[center] >
   show( width,  ( i = 0; i < width; i++ ( j = 0; j < height; j++ (i == 0 || j == 0 || i == width - 1 || j == height - 1"*"" "
//for循环打印菱形public class Rhombus {public void show(int height) {int half = height / 2;for (int i = 1; i <= half; i++) {// 先打空格for (int j = half - i + 1; j > 0; j--) {
                System.out.print(" ");
            }for (int j = 0; j < 2 * i - 1; j++) {
                System.out.print("*");
            }
            System.out.println();
        }for (int i = 0; i < 2 * half + 1; i++) {
            System.out.print("*");
        }
        System.out.println();for (int i = 1; i <= half; i++) {// 先打空格for (int j = i; j > 0; j--) {
                System.out.print(" ");
            }for (int j = 0; j < 2 * (half - i) + 1; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

}
//for循环打印等腰三角形public class Isosceles {public void show(int height) {for (int i = 1; i <= height; i++) {// 先打空格for (int j = height - i; j > 0; j--) {
                System.out.print(" ");
            }for (int j = 0; j < 2 * i - 1; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
//for循环打印之间三角形public class Triangle {public void show(String str, int height) {for (int i = 0; i < height; i++) {for (int j = 0; j < i + 1; j++) {
                System.out.print(str);
            }
            System.out.println();
        }
    }

}

以上就是选择、冒泡排序,二分查找法的用法详解的详细内容,更多请关注其它相关文章!