易截截图软件、单文件、免安装、纯绿色、仅160KB

python算法实践4 快速排序

#快速排序
def Partition(mylist, low, high):
tmp = mylist[low]
while low < high:
while low < high and mylist[high] >= tmp:
high = high - 1
if low < high:
mylist[low] = mylist[high]
low = low + 1
while low < high and mylist[low] <= tmp:
low = low + 1
if low < high:
mylist[high] = mylist[low]
high = high - 1
mylist[low] = tmp
return low
def QuickSort(mylist, low, high):
if low < high:
pivotpos = Partition(mylist, low, high)
QuickSort(mylist, low, pivotpos - 1)
QuickSort(mylist, pivotpos + 1, high)
mylist0 = [11, 10, 3, 12, 33, 1000, 1, 333, -11]
QuickSort(mylist0, 0, len(mylist0) - 1)
print(mylist0)


相关文档:

python 如何返回多个值

如何写一个返回多个值的函数
函数的return 语句只能返回一个值,可以是任何类型。
因此,我们可以“返回一个 tuple类型,来间接达到返回多个值
”。
例:   x 除以 y 的余数与商的函数
def    F1 ( x, y ):
         a = x % y
  ......

很全的Python资源收集

Programming Python, 2nd Edition (O'Reilly)
http://www.osbbs.com/dl/Programming Python, 2nd Edition (O'Reilly).chm
很全很经典了python学习入门资料
OReilly - Learning Python:
http://www.osbbs.com/dl/OReilly - Learning Python.chm ......

python string和PyQt的QString的区别

python string和PyQt的QString的区别 以下在Python2.6和PyQt4.4.4 for
Python2,6环境下讨论: Python中有两种有关字符的类型:Python string object和Python Unicode
object。主要使用Python string object进行数据输入输出。 PyQt中与之相对应的字符有关类
python string和PyQt的QString的区别
以下在Python2.6和PyQt4 ......

example of python operator overloadind

And last here is the overload operators example:
# map() takes two (or more) arguments, a function and a list to apply the function to
# lambda can be put anywhere a function is expected
# map() calls lambada for every element in the self list
# since Vector has overloaded __getitem__ and __len_ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号