Skip to content
Snippets Groups Projects

Shuttle sort

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by EDSamoseeva

    Homework for algorithmic languages and programming

    sort.py 742 B
    a = [0] * int(input())
    for i in range(len(a)):
        a[i] = int(input()) #нужно вводить построчно, иначе это будет считаться списком, а не отдельными числами
    left = 0
    right = len(a)-1
    while left <= right:
        for i in range (left, right): #сортировка с начала, как в оригинальном методе камня
            if a[i]>a[i+1]:
                a[i], a[i+1] = a[i+1], a[i]
    
        for i in range (right, left, -1): #обратный предыдущему цикл
            if a[i-1] > a[i]:
                a[i-1], a[i] = a[i], a[i-1]
    
        left = left + 1 #сокращаем сортируюмую часть списка
        right = right - 1
    print(a)
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment