Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def insertion_sort(x):
- ops = 0
- for i in range(1, len(x)):
- reiksme = x[i]
- n = i - 1
- # while reiksme >= x[n] and n >= 0:
- # naudojant sita ^ gaunas blogesnis efektyvumas, bet gal salyga to praso (nedidejanciai)
- while reiksme > x[n] and n >= 0:
- ops += 1
- x[n + 1] = x[n]
- n -= 1
- x[n + 1] = reiksme
- return ops
- masyvas = [1, 5, 4, 2, 3, 4]
- print("Nerikiuotas masyvas:")
- print(masyvas)
- ops = insertion_sort(masyvas)
- print("Surikiuotas masyvas:")
- print(masyvas)
- print("Operaciju skaicius:")
- print(ops)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement