Path: news.cnusenet.org!news.cn99.com!not-for-mail
From: "cigarette" <dragonz@21cn.com>
Newsgroups: cn.bbs.comp.lang.python
Subject: Re: return语句引起的灵异事件
Date: Thu, 21 Jun 2007 21:43:35 +0800
Organization: Bentium Ltd. (CN99)
Lines: 44
Message-ID: <f5e1ii$ul5$1@news.cn99.com>
References: <f5dv4o$t1c$3@news.cn99.com>
NNTP-Posting-Host: 61.144.66.26
X-Trace: news.cn99.com 1182435730 31397 61.144.66.26 (21 Jun 2007 14:22:10 GMT)
X-Complaints-To: usenet@news.cn99.com
NNTP-Posting-Date: Thu, 21 Jun 2007 14:22:10 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
Xref: news.cnusenet.org cn.bbs.comp.lang.python:22931

没发现问题,python2.5.1

"XiaQ" <xiaqqaix@163.com> 写入消息新闻:f5dv4o$t1c$3@news.cn99.com...
> 我在Python里实现插入排序,代码如下:
> def InsSort(li):
>     """ InsSort(li) -- Insertion Sort *IN PLACE*. """
>     for j in range(1, len(li)):
>         key = li[j]
>         i = j - 1
>         while i >=0 and li[i] > key:
>             li[i+1] = li[i]
>             i -= 1
>         li[i+1] = key
>     #return li
> 测试一切正常。但是,我在它的末尾加上了了一句
> return li(原代码中这一句被注释掉了)
> 却怎么都不对了。应该不是版本问题(我在Python 2.5,IronPython 1.1里都测试 
> 过了),望高手解答!
>
> 顺便写了一个测试suite:
> import random
> def RandomList(n = 10):
>     li = []
>     for i in range(n):
>         li.append(random.random())
>     return li
>
> def InsSort(li):
>     """ InsSort(li) -- Insertion Sort *IN PLACE*. """
>     for j in range(1, len(li)):
>         key = li[j]
>         i = j - 1
>         while i >=0 and li[i] > key:
>             li[i+1] = li[i]
>             i -= 1
>         li[i+1] = key
>     #return li
>
> if __name__ == '__main__':
>     li = RandomList()
>     InsSort(li)
>     print li