Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
H.W5
#python 3.5.2 print ("Hello, world!") #----------------------------H.W 5--------------------------------------------------------------------------- #----------------------------Bubble sort in descending order (for loop)------------------------------------- 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 = [100, 5, 105, 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) #-----------------------Bubble sort in descending order (while)------------------------------------- def x(y): length=len(y) p=length-1 while p<length: print ('p: ', p) i=length-1 while i<((length-1)): print ('Possible values for i:',i) if y[i-1] > y[i]: temp = y[i-1] y[i-1] = y[i] y[i] = temp print (i,'-->',y) i=i-1 print () p=p-1 print ('------------------------------------------------') return y Input=[3,1,1,5,2] print('y=',Input) R=x(Input) print('R=',R) #-----------------------Selection sort in descending order (for/while)-------------------------------------
run
|
edit
|
history
|
help
0
Nearest Prime Number
Python Practice
emoji
Pierwiastkowanie
quizcorrect
SceneGraph Interviewee Task
Hi
shuru14
try1
fibonacciseries