Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

pythonË㷨ʵ¼ù6 ¶ÑÅÅÐò

#¶ÑÅÅÐò
def Heapify(mylist, start, end):
left = 0
right = 0
maxv = 0
left = start * 2
right = start * 2 + 1
while left <= end:
maxv = left
if right <= end:
if mylist[left] < mylist[right]:
maxv = right
else:
maxv = left
if mylist[start] < mylist[maxv]:
tmp = mylist[maxv]
mylist[maxv] = mylist[start]
mylist[start] = tmp
start = maxv
else:
break
left = start * 2
right = start * 2 + 1

def BuildHeap(mylist):
size = len(mylist)
i = (size -1) // 2;
while i >= 0:
Heapify(mylist, i, size - 1)
i = i - 1

def HeapSort(mylist):
BuildHeap(mylist)
i = len(mylist) - 1

while i >= 0:
tmp = mylist[0]
mylist[0] = mylist[i]
mylist[i] = tmp

Heapify(mylist, 0, i - 1)
i = i - 1

mylist0 = [11, 23, 1, 24, 112, 200, 9, 32]
HeapSort(mylist0)
print(mylist0)


Ïà¹ØÎĵµ£º

ÔÚWindowsÏÂʹÓÃPython±à³Ì

Ò»¡¢Ê¹ÓÃPythonÐèÒªÖªµÀµÄ
ÔÚ Windows ÉÏ£¬°²×° Python ÓÐÁ½ÖÖÑ¡Ôñ¡£
1¡¢ActiveState ÖÆ×÷µÄ ActivePython ÊÇרÃÅÕë¶Ô Windows µÄ Python Ì×¼þ£¬Ëü°üº¬ÁËÒ»¸öÍêÕûµÄ Python ·¢²¼¡¢Ò»¸öÊÊÓÃÓÚPython ±à³ÌµÄ IDE ÒÔ¼°Ò»Ð© PythonµÄ Windows À©Õ¹£¬ÌṩÁËÈ«²¿µÄ·ÃÎÊ Windows APIs µÄ·þÎñ£¬ÒÔ¼° Windows×¢²á±íµÄ×¢²áÐÅÏ¢¡£ËäÈ ......

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 ......

python×Ö·û´®Ê¹ÓÃ×ܽá



À´Ô´:
×÷Õß:
Áé½£
1.python ×Ö·û´®Í¨³£Óе¥ÒýºÅ£¨'...'£©¡¢Ë«ÒýºÅ£¨...£©¡¢ÈýÒýºÅ£¨...£©»ò£¨'''...'''£©°üΧ£¬ÈýÒýºÅ°üº¬µÄ×Ö·û´®¿ÉÓɶàÐÐ×é³É£¬Ò»°ã¿É±íʾ´ó¶ÎµÄÐðÊöÐÔ×Ö·û´®¡£ÔÚʹÓÃʱ»ù±¾Ã»Óвî±ð£¬

1.python
×Ö·û´®Í¨³£Óе¥ÒýºÅ£¨'...'£©¡¢Ë«ÒýºÅ£¨"..."£©¡¢ÈýÒýºÅ£¨"""... ......

Python Ïß³Ìͬ²½

¶à¸öÖ´ÐÐÏ߳̾­³£Òª¹²ÏíÊý¾Ý£¬Èç¹û½ö½ö¶ÁÈ¡¹²ÏíÊý¾Ý»¹ºÃ£¬µ«ÊÇÈç¹û¶à¸öÏß³ÌÒªÐ޸Ĺ²ÏíÊý¾ÝµÄ»°¾Í¿ÉÄܳöÏÖÎÞ·¨Ô¤ÁϵĽá¹û¡£
    ¼ÙÈçÁ½¸öÏ̶߳ÔÏót1
ºÍt2
¶¼Òª¶ÔÊýÖµnum=0
½øÐÐÔö1ÔËË㣬ÄÇôt1
ºÍt2
¶¼¸÷¶Ônum
ÐÞ¸Ä10
´ÎµÄ»°£¬ÄÇônum
×îÖյĽá¹ûÓ¦¸ÃΪ20
¡£µ«ÊÇÈç¹ûµ±t1
È¡µÃnum
µÄֵʱ£¨¼ÙÈç´Ë ......

pythonË㷨ʵ¼ù2 shellÅÅÐò

#shellÅÅÐò
def ShellPass(mylist, d):
size = len(mylist)
i = d
while i < size:
if mylist[i] < mylist[i - d]:
tmp = mylist[i]
j = i - d
mylist[j + d] = mylist[j]
j = j - d
while j >= 0 and mylist[j] > ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ