Grapefruit class - phase 4

Keywords: Java Back-end


That day TA said TA was coming, so I came.
I said I was coming that day, so you came.
What did TA see?
What do you see?
I see you together, I'm really happy:)

Yang Sai's song and the other two volunteers tell their story of 2050. They can see the light and enthusiasm of young people in their eyes.

Interested parties can join:

Spring Boot,Spring Cloud , Mybatis

Spring Boot

Spring Boot is a new framework provided by pivot team. It is designed to simplify the initial construction and development process of new spring applications. The framework uses a specific way to configure, so that developers no longer need to define templated configurations. In this way, Spring Boot is committed to becoming a leader in the booming field of rapid application development.

Spring Cloud

Spring Cloud is an ordered collection of frameworks. Taking advantage of the development convenience of Spring Boot, it cleverly simplifies the development of distributed system infrastructure, such as service discovery and registration, configuration center, message bus, load balancing, circuit breaker, data monitoring, etc., which can be started and deployed with one click with the development style of Spring Boot. Spring Cloud does not repeatedly manufacture wheels. It just combines the relatively mature and practical service frameworks developed by various companies, re encapsulates them through the Spring Boot style, shields the complex configuration and implementation principles, and finally leaves a set of simple, easy to understand, easy to deploy and easy to maintain distributed system development toolkit for developers.

Hand tear sorting

Bubble sorting

Algorithm steps:

Compare adjacent elements. If the first one is bigger than the second, exchange them.
Do the same for each pair of adjacent elements, from the first pair at the beginning to the last pair at the end. After this step, the last element will be the maximum number.
Repeat the above steps for all elements except the last one.
Continue to repeat the above steps for fewer and fewer elements at a time until no pair of numbers need to be compared.

public static void sort(int arr[]) {
    for (int i = 0; i < arr.length - 1; i++) {
        boolean flag = false;
        for (int j = 0; j < arr.length - 1 - i; j++) {
               if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    flag = true;
        if (flag == false) {

Insert sort

Algorithm steps:

The first element of the first sequence to be sorted is regarded as an ordered sequence, and the second element to the last element is regarded as an unordered sequence.
Scan the unordered sequence from beginning to end, and insert each scanned element into the appropriate position of the ordered sequence. (if the element to be inserted is equal to an element in the ordered sequence, the element to be inserted is inserted after the equal element.)

public static void doInsertSort(int[] array) {
    for (int index = 1; index < array.length; index++) 
        int temp = array[index];
        int leftindex = index - 1;
        while (leftindex >= 0 && array[leftindex] > temp) {
            array[leftindex + 1] = array[leftindex];
        array[leftindex + 1] = temp;

Quick sort

Pick out an element from the sequence, which is called "pivot";
Reorder the sequence. All elements smaller than the benchmark value are placed in front of the benchmark, and all elements larger than the benchmark value are placed behind the benchmark (the same number can be on either side). After the partition exits, the benchmark is in the middle of the sequence. This is called a partition operation;
Recursively sort the subsequence less than the reference value element and the subsequence greater than the reference value element;

public class QuickSort {
    private static void quickSort(int[] arr, int low, int high) {
        if (low < high) {
            int index = getIndex(arr, low, high);
            quickSort(arr, low, index - 1);
            quickSort(arr, index + 1, high);
    private static int getIndex(int[] arr, int low, int high) {
        int tmp = arr[low];
        while (low < high) {
            while (low < high && arr[high] >= tmp) {
            arr[low] = arr[high];
            while (low < high && arr[low] <= tmp) {
            arr[high] = arr[low];
        arr[low] = tmp;
        return low;

Posted by wdsmith on Sun, 31 Oct 2021 14:56:34 -0700