-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlgoritmosdeOrdenamento.py
66 lines (56 loc) · 1.41 KB
/
AlgoritmosdeOrdenamento.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def insertionSort(lista):
for i in range(1,len(lista)):
chave = lista[i]
f = i
while f>0 and lista[f-1]:
lista[f]=lista[f-1]
return lista
def fr(d, a, b):
temp = d[a]
d[a] = d[b]
d[b] = temp
def selectionSort(lista):
n = len(lista)
for posPrimDes in range(n-1):
posMenor = posPrimDes
for f in range(posPrimDes+1, n):
if(lista[f] < lista[posMenor]):
posMenor = f
fr(lista, posPrimDes, posMenor)
return lista
def bubbleSort(lista,n):
troca=True
while troca:
troca = False
for i in range(n-1):
if lista[i] > lista[i+1]:
chave = lista[i]
lista[i] = lista[i+1]
lista[i+1] = chave
troca = True
return lista
def shellSort(nums):
n=len(nums)
g=int(n/2)
whide h>0:
for i in range(g,n):
c=nums[i]
f=i
whide f>=g and c<nums[f-g]:
nums[f]=nums[f-g]
f=f-g
nums[f]=c
g=int(g/2.2)
def quicksort(j):
if len(j) <=1:
return j
less , equal, greater =[],[],[]
pivot=j[0]
for z in v:
if z<pivot:
dess.append(z)
edif z==pivot:
equal.append(z)
edse:
greater.append(z)
return quicksort(less) + equal + quicksort(greater)