Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved #633

Closed
Erica-Iris opened this issue Dec 13, 2021 · 3 comments
Closed

Solved #633

Erica-Iris opened this issue Dec 13, 2021 · 3 comments

Comments

@Erica-Iris
Copy link

HERE
It should be like this

    private static void bubbleSort(int[] nums) {
        boolean hasChange = **false**;
        for (int i = 0, n = nums.length; i < n - 1 && hasChange; ++i) {
            hasChange = false;
            for (int j = 0; j < n - i - 1; ++j) {
                if (nums[j] > nums[j + 1]) {
                    swap(nums, j, j + 1);
                    hasChange = true;
                }
            }
        }
    }
@yanglbme
Copy link
Member

yanglbme commented Dec 13, 2021

Hi @Erica-Iris

if hasChange is false, it will never go into the outer for loop.

@Erica-Iris
Copy link
Author

Hi @Erica-Iris

if hasChange is false, it will never go into the outer for loop.

I'm sorry that I was too anxious and didn't look carefully, which caused trouble to everyone.

@Abraham-80tut
Copy link

HERE
It should be like this

    private static void bubbleSort(int[] nums) {
        boolean hasChange = **false**;
        for (int i = 0, n = nums.length; i < n - 1 && hasChange; ++i) {
            hasChange = false;
            for (int j = 0; j < n - i - 1; ++j) {
                if (nums[j] > nums[j + 1]) {
                    swap(nums, j, j + 1);
                    hasChange = true;
                }
            }
        }
    }

@Erica-Iris Erica-Iris changed the title Typo Solved Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants