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

请教一下冒泡排序中,for passnum in range(len(alist)-1, 0, -1)为什么要这样写range(len(alist)-1,0,-1) #24

Open
emmalovestudy opened this issue Jun 8, 2020 · 1 comment

Comments

@emmalovestudy
Copy link

No description provided.

@LucisXu
Copy link

LucisXu commented Jul 10, 2020

第一次循环是需要循环到最后一个数,因此第一次的下标为len(alist)-1即最后一个数,第一次循环结束后最后一个数最大,也就意味着下一次的循环到倒数第二个数即可,因此括号里最后为-1。依次类推直到第二个数,因此括号的中间为0。

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