In [1]:
L = [3, 1, 2, 5, 0, -1, 4]
L.sort()
In [2]:
L
Out[2]:
In [3]:
L.sort(reverse=True)
L
Out[3]:
In [4]:
razred = [
"Nenadović, Nenad",
"Petrović, Petar",
"Milanović, Milan",
"Anić, Ana",
"Vuković, Vuk",
"Sarić, Sara"
]
In [5]:
razred.sort()
razred
Out[5]:
In [6]:
razred = [
"Ненадовић, Ненад",
"Петровић, Петар",
"Милановић, Милан",
"Анић, Ана",
"Вуковић, Вук",
"Сарић, Сара"
]
In [7]:
razred.sort()
razred
Out[7]:
In [2]:
razred = [["Ana", "ž", 13, 46, 160],
["Bojan", "m", 14, 52, 165],
["Vlada", "m", 13, 47, 157],
["Gordana", "ž", 15, 54, 165],
["Dejan", "m", 15, 56, 163],
["Đorđe", "m", 13, 45, 159],
["Elena", "ž", 14, 49, 161],
["Žaklina", "ž", 15, 52, 164],
["Zoran", "m", 15, 57, 167],
["Ivana", "ž", 13, 45, 158],
["Jasna", "ž", 14, 51, 162]]
In [9]:
def selection_sort(L):
n = len(L)
if n <= 1: return
for i in range (n-1):
m = i
for j in range(i+1,n):
if L[j] < L[m]: m = j
L[i], L[m] = L[m], L[i]
In [4]:
razred
Out[4]:
In [3]:
def selection_sort_by(k, L):
n = len(L)
if n <= 1: return
for i in range (n-1):
m = i
for j in range(i+1,n):
# ovde poredimo vrednosti na k-tom mestu u redu L[j] i L[m]
if L[j][k] < L[m][k]: m = j
L[i], L[m] = L[m], L[i]
In [9]:
selection_sort_by(4, razred)
razred
Out[9]:
In [8]:
selection_sort_by(2, razred)
razred
Out[8]:
In [10]:
def bubble_sort(L):
n = len(L)
if n <= 1: return
zamena = True
while zamena:
zamena = False
for i in range(n-1):
if L[i] > L[i+1]:
zamena = True
L[i], L[i+1] = L[i+1], L[i]
n -= 1
In [3]:
def bubble_sort_by(k, L):
n = len(L)
if n <= 1: return
zamena = True
while zamena:
zamena = False
for i in range(n-1):
# ovde poredimo vrednosti na k-tom mestu u redu L[i] i L[i+1]
if L[i][k] > L[i+1][k]:
zamena = True
L[i], L[i+1] = L[i+1], L[i]
n -= 1
In [4]:
bubble_sort_by(3, razred)
razred
Out[4]:
In [15]:
razred = [
["Dejan", "Dejanović", 3, 4, 5, 4, 5],
["Mara", "Marić", 4, 5, 5, 4, 2],
["Miloš", "Milošević", 2, 5, 4, 3, 3],
["Petar", "Marković", 5, 4, 5, 5, 5]
]
In [14]:
takmicenje = [
["Dejan", 25, 25, 0, 25],
["Mira", 25, 0, 20, 25],
["Milan", 0, 0, 10, 0],
["Milica", 25, 25, 25, 25],
["Nenad", 10, 0, 25, 5]
]
No comments:
Post a Comment