Skip to content

A bug in the basic implementation #1

@terizhao

Description

@terizhao

def bubble_sort(array):
17 lenth = len(array)
18
19 for i in range(lenth):
20 flag = True
21 for j in range (1, lenth): # it should be array's length other than array's length -1.
22 if (array[j-1]<array[j]):
23 array[j],array[j-1]=array[j-1],array[j]
24 flag = False
25
26 if flag:
27 break
28 print array
29 return array

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions