associação pythonbrasil[11] django zope/plone planet Início Logado como (Entrar)

Revisão 1e 2004-09-18 00:37:25

Excluir mensagem

QuickSort

Script de ordenação rádida.

  • #!/usr/bin/env python
  • def partition(list, start, end):
    • pivot = list[end] last value bottom = start-1 top = end done = 0 while not done:
      • while not done:
        • bottom = bottom+1 if bottom == top:
          • done = 1 break

          if list[bottom] > pivot:

          • list[top] = list[bottom] break
        while not done:
        • top = top-1 if top == bottom:
          • done = 1 break

          if list[top] < pivot:

          • list[bottom] = list[top] break
      list[top] = pivot return top
    def quicksort(list, start, end):
    • if start < end:

      • split = partition(list, start, end) quicksort(list, start, split-1) quicksort(list, split+1, end)
      else:
      • return

    if name=="main":

    • import sys list = map(int,sys.argv[1:]) start = 0 end = len(list)-1 quicksort(list,start,end) import string print string.join(map(str,list))