vetor1 = [1,5,9,111,5,6,3,8,15,18963,1,0,159,3,3,3,-1] #selection sort --> print(vetor1) def selection_sort (vetor): for i in range(0,len(vetor)): for j in range(0,len(vetor)): if vetor[i]<vetor[j]: vetor[i],vetor[j] = vetor[j],vetor[i] print (vetor1) return vetor #insercion sort --> def insercion_sort(vetor): for i in range(len(vetor)): te = i while te !=0 and vetor[te]<vetor[te-1]: vetor[te],vetor[te-1] = vetor[te-1],vetor[te] te = te-1 print (vetor1) return vetor #bubble sort --> def bubble_sort(vetor): tamanho = len(vetor) while tamanho != 0: for i in range(len(vetor)-1): if vetor[i] > vetor[i+1]: vetor[i],vetor[i+1] = vetor[i+1],vetor[i] tamanho = tamanho-1 return vetor #print(selection_sort(vetor1)) print(insercion_sort(vetor1)) #print(bubble_sort(vetor1))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question