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

冒泡排序完全是错的 #60

Open
Soul-Killer-Ky opened this issue Mar 6, 2022 · 1 comment
Open

冒泡排序完全是错的 #60

Soul-Killer-Ky opened this issue Mar 6, 2022 · 1 comment

Comments

@Soul-Killer-Ky
Copy link

冒泡排序是通过数去找位置,这里的冒泡排序写成选择排序了,附代码

func bubbleSort(arr []int) []int {
	if len(arr) == 0 {
		return arr
	}
	n := len(arr)
	for i := 0; i < n-1; i++ {
		for j := 0; j < n-1-i; j++ {
			if arr[j] > arr[j+1] {
				arr[j], arr[j+1] = arr[j+1], arr[j]
			}
		}
	}
	return arr
}
@xxiaocheng
Copy link

确实是不正确

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

2 participants