Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
H.W 5-Solution
#python 3.5.2 print ("Hello, world!") #----------------------------H.W 5------------------------------------- def bubbleSort(alist): # do all operations here length = len(alist) # length = 4 (in this example) for passnumber in range(length-1,0,-1): # number of passes = N - 1 print ('Passnumber: ', passnumber) for i in range((length-1) ,0,-1 ): # loop for bubbles print ('Possible values for i:',i) if alist[i-1] > alist[i]: temp = alist[i-1] # temp = 89 alist[i-1] = alist[i] # 89 with 5 alist[i] = temp # 89 => 5 print (i,'-->',alist) print () print ('------------------------------------------------') return alist sampleList = [105, 100, 5, 89, 8, 23, 1] # Length = N # pass = N - 1 times # pass 1 - [--, --, --, 89] # pass 2 - [--, --, 24, 89] # pass 3 - [--, 8, 24, 89] print (sampleList) sortedList = bubbleSort(sampleList) print (sortedList)
run
|
edit
|
history
|
help
0
RANDOM NUMBER
Square-Triangle Numbers
Magic Calendar of any month
python, Polymorphie, attributes, setter and getter the pythonic way (V3)
PyCutRod
Your mom
pytest
Hello
hi
ConstructorBehaviourInInheritance