2006年07月10日 星期一 17:36
用如下代码, >>> t7=BinaryTree(1) >>> t7.addNode(2) >>> t7.addNode(3) 一直到100,会是一条很长的树,有什么办法balance吗? class BinaryTree: def __init__(self, key, left=None, right=None, parent=None): self.key = key self.left = left self.right = right self.parent = parent def __str__(self): return str(self.left) return str(self.key) def addNode(self,key): """Add a node in the proper location.""" if key < self.key: if self.left: self.left.addNode(key) else: self.left = BinaryTree(key, parent=self) elif key > self.key: if self.right: self.right.addNode(key) else: self.right = BinaryTree(key, parent=self)
2006年07月10日 星期一 17:40
没有实现树查找功能. ----- Original Message ----- From: "linda.s" <samrobertsmith at gmail.com> To: <python-chinese at lists.python.cn> Sent: Monday, July 10, 2006 5:36 PM Subject: [python-chinese] balance2叉树 > 用如下代码, >>>> t7=BinaryTree(1) >>>> t7.addNode(2) >>>> t7.addNode(3) > 一直到100,会是一条很长的树,有什么办法balance吗? > > class BinaryTree: > > def __init__(self, key, left=None, right=None, parent=None): > self.key = key > self.left = left > self.right = right > self.parent = parent > > def __str__(self): > return str(self.left) > return str(self.key) > > def addNode(self,key): > """Add a node in the proper location.""" > if key < self.key: > if self.left: > self.left.addNode(key) > else: > self.left = BinaryTree(key, parent=self) > elif key > self.key: > if self.right: > self.right.addNode(key) > else: > self.right = BinaryTree(key, parent=self) > -------------------------------------------------------------------------------- > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese
2006年07月10日 星期一 17:44
ʹÓÃpython2.4 apache2 mod_python-3.2.5b.win32-py2.4 ÊÇfrom mod_python import * ʱ£¬³öÏÖÒÔÏ´íÎó File "C:\Python\lib\site-packages\mod_python\apache.py", line 31, in ? import _apache ImportError: No module named _apache ÓÐÄÄλÐÖµÜÖªµÀÊÇʲôÔÒò°¡ ÇëÖ¸µã£¬²»Ê¤¸Ð¼¤°¡£¡ >From: python-chinese-request at lists.python.cn >Reply-To: python-chinese at lists.python.cn >To: python-chinese at lists.python.cn >Subject: python-chinese Digest, Vol 31, Issue 72 >Date: Mon, 10 Jul 2006 17:41:16 +0800 (HKT) > >Send python-chinese mailing list submissions to > python-chinese at lists.python.cn > >To subscribe or unsubscribe via the World Wide Web, visit > http://python.cn/mailman/listinfo/python-chinese >or, via email, send a message with subject or body 'help' to > python-chinese-request at lists.python.cn > >You can reach the person managing the list at > python-chinese-owner at lists.python.cn > >When replying, please edit your Subject line so it is more specific >than "Re: Contents of python-chinese digest..." > > >Today's Topics: > > 1. Re: [django] ????? ?????? (newboytim) > 2. Re: [django] ????? ?????? (swordsp) > 3. Re: [django] ????? ?????? (Xiao Lei Wu) > 4. balance2?? (linda.s) > 5. Re: balance2?? (netkiller) > > >---------------------------------------------------------------------- > >Message: 1 >Date: Mon, 10 Jul 2006 16:04:46 +0800 >From: "newboytim" <newboytim at 163.com> >Subject: Re: [python-chinese] [django] ????? ?????? >To: <python-chinese at lists.python.cn> >Message-ID: <00d801c6a3f7$86e71aa0$ea0115ac at design6> >Content-Type: text/plain; charset="gb2312" > >¹þ¹þ >ÕâÑùµÄÎÊÌâû±ØÒªÌÖÂÛ > >Èç¹ûÉæ¼°µ½ÉÌÒµµÄÊÂÇé >²»Äܵ¥Óü¼Êõ½Ç¶ÈÀ´¿´ > ----- Original Message ----- > From: swordsp > To: python-chinese at lists.python.cn > Sent: Monday, July 10, 2006 3:42 PM > Subject: Re: [python-chinese] [django] Ò»¸öÀÏÎÊÌâ ¹ØÓÚÊý¾Ý´¦Àí > > > > > > On 7/10/06, Xiao Lei Wu <xiaoleiw at cn.ibm.com> wrote: > python-chinese-bounces at lists.python.cn дÓÚ 2006-07-10 14:19:44: > > > ÎÒÕâÀï±¾À´¾ÍÔÚ˵"ÉÌÒµÂß¼"µÄÊÂÇ飬×ÔÈ»²»ÊÇʲô"Ò»°ãµÄͨÓÃÉè¼Æ"¡£ÔÙ˵£¬ ¶ÔÓÚÊý¾Ý¿âÀ´Ëµ£¬ÓÉÓÚÉÌÒµÓ¦ÓÃÕ¼80%ÒÔÉϵıÈÀý£¬ËùÒÔÉÌÒµÓ¦ÓþÍÊÇ"Ò»°ãµÄͨÓÃÉè¼Æ "¡£ > > ºÕºÕÓÐÃûµÄLAMP×éºÏ¾ÍÕâÑù±»ÄãÅųý³öÊý¾Ý¿âÓ¦Óõķ¶³ëÁË-_-b > µ¥´¿ÂÛÓ¦ÓÃÊýÁ¿µÄ»°£¬Õâ¿ÉÊdz¬¹ýÊÀ½çÉÏËùÓÐÉÌÒµÊý¾Ý¿âµÄ²¿ÊðÁ¿×ܺϰɣ¿ > > > > ÎÒ³ÐÈÏÎÒÕâ¸ö"×î"×ÖÓеã¿äÕÅ£¬"¹Ü¼ÒÆÅ"Ò²ËãÊǽøÏú´æÈí¼þ°É£¬ËûÊÇÎÒ¼û¹ý×î¼ò ½àµÄÁË£¬ËƺõÓÃAccessʵÏֵģ¬²»¹ýAccessÖÁÉÙ»¹Ö§³ÖÊÂÎñºÍËø£¬±ÈMySQLÉÙάǿһ µã¡£"ËÙ´ï"ÉÔ΢¸´ÔÓһЩ£¬ÓõÄÊÇBorlandµÄÄǸö½ÐʲôÀ´×ŵÄÊý¾Ý¿â£¬½éÓÚAccessºÍ PostgreSQLÖ®¼ä£¬Òª±ÈMySQL¸´ÔÓ²»ÉÙ¡£ > > Èç¹ûÄã˵×Ó²éѯ¡¢ÊÓͼ¡¢´¥·¢Æ÷ºÍ´æ´¢¹ý³ÌÕâЩ5.0µÄÐÂfeature»¹²»¹»³ÉÊìÄÇÒ²¾Í ËãÁË...MySQL ²»Ö§³ÖÊÂÎñºÍËø£¿ÕⶼÊÇÄĸö°æ±¾µÄÊÂÇé°¡£¿ > > > Õû¸öÉç»áÔÚ½ø²½£¬ITÔÚÉÌÒµÁìÓòÖеÄʹÓÃÒ²ÔÚ½ø²½£¬"foxproÕâÀàµÄ¾Í×ãÒÔÍê³É" ÕâÊÇNÄêÒÔÇ°µÄ¹Ûµã¡£Èç¹ûÔÚFoxproµÄÄê´úÓÐMySQLµÄ»°£¬ÎÒÏëºÜ¶àÈË»áÑ¡ÔñºóÕß¡£ > ÖÁÓÚΪʲôÉÌÒµÂß¼ÒªÄÇô¸´ÔÓ£¬ÕâÎÒÒ»Á½¾ä»°¸øÄã½âÊͲ»Çå³þ£¬Èç¹ûÄãÓÐÐËȤ £¬Äã¿ÉÒÔÈ¥Ñо¿Compiere > > ²»Í¬µÄÁìÓòÓв»Í¬µÄÐèÇó£¬ÎÒËùÔڵĹ«Ë¾Ò²ÊÇר¸øÊÀ½ç500Ç¿µÄÆóÒµ×öserviceµÄ £¬postgresqlºÍsqlserverµÄʹÓôó¸Å¸÷°ë¡£ > ²»¹ý³ýÁËÎȶ¨ÐÔºÍÉÌÒµÒòËصĿ¼ÂÇÖ®Í⣬µ¥´Ó¹¦ÄÜÉÏÀ´ËµÓÐÒ»°ëµÄÏîÄ¿»»³Émysql ÆäʵҲδ³¢²»¿É¡£ > > > > > ÎÒÏë˵µÄÊÇ£¬Õë¶ÔÓÚijÈËÖ¸³öÓóÌÐòºÍʵ¼Ê"ÈÆ¿ª"һЩ¸ß¼¶SQLÌØÐÔ£¬ÊÇÐèÒªÏà µ±´óÄѶȵģ¬µÃ²»³¥Ê§£¬Ðú±ö¶áÖ÷¡£Òò´ËÎÒÃÇÓ¦¸ÃÌôÑ¡ºÏÊʵÄÊý¾Ý¿âÈ¥Óöø²»ÊDZà³É" ÈÆ¿ª" > > > > ÇÒ²»ËµÄÇЩÉÌÒµÊý¾Ý¿â£¬postgresqlµÄ²¿Êð¡¢ÅäÖñÈmysql¶¼ÒªÂé·³²»ÉÙ£¬Ïà¹ØÖÜ ±ß¹¤¾ßÎĵµµÄÖ§³Ö³Ì¶ÈÒ²Òª²îºÜ¶à£¬ÊìϤpostgresqlµÄÊý¾Ý¿â¹ÜÀíÔ±Ò²ÒªÉٺܶࡣ > ÆäʵÎÒҲϲ»¶postgresql£¬µ«ÊǶÔÓÚÖÐСÐÍÏîÄ¿À´Ëµ£¬Ò²Óкܶà²ÉÓÃmysqlµÄÀíÓÉ £¬²»ÄÜÈÃÄãÕâÑùÒ»°ô×Ó´òËÀÁË¡£ > > > > >------------------------------------------------------------------------------ > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese >-------------- next part -------------- >An HTML attachment was scrubbed... >URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060710/4af8e364/attachment.html > >------------------------------ > >Message: 2 >Date: Mon, 10 Jul 2006 17:01:32 +0800 >From: swordsp <sparas2006 at gmail.com> >Subject: Re: [python-chinese] [django] ????? ?????? >To: python-chinese at lists.python.cn >Message-ID: > <ada565b50607100201u2fa65e17n48ee07853f38b4c4 at mail.gmail.com> >Content-Type: text/plain; charset="gb2312" > >ÎÒÓÃMySQLµÄʱºò»¹²»ÈçÓÃPostgreSQLµÄʱºò¶àÄØ£¬ÓÐʲôºÃ¿ñÈȵÄ... >"MySQL²»ÊʺÏÆóÒµ¼¶Ó¦ÓÃ"ÕâÒ»µãÎÒÒ²ºÜÔÞͬÄ㣬µ«"MySQLÊÇÍæ¾ß"ºÍ"MySQL³Ðµ£²»ÁË ÉÌÒµÒµÎñÂß¼"ÊÇÎÒ²»ÈÏͬµÄ¡£ >ÎÒÖ»ÊÇÏ£ÍûÔÚÓʼþÁбíÖо¡Á¿´«´ïÕýÈ·È«ÃæµÄÐÅÏ¢£¬±ÈÈç"MySQL²»Ö§³ÖÊÂÎñºÍËø"¾ÍºÜ Ã÷ÏÔÊÇ»á¸ø±ðÈËÒÔÎóµ¼µÄÐÅÏ¢£¬¡ª¡ªµ±È»Èç¹ûÎÒʲôµØ·½Îóµ¼Á˱ðÈËÄÇôÇ뾡Á¿²ÈÎÒ²» Òª¿ÍÆø£¬ÎÒÒ»ÏòÈÏΪÔÚÌÖÂÛÖвÈÓë±»²ÈÊÇ¿ªÍØÑÛ½çµÄºÃ°ì·¨¡£ > >Anyway£¬Èç¹ûÎÒµÄÑÔ´ÊÈÃÄã¾õµÃÊÇ"ÉϸÙÉÏÏß¿ÚÖï±Ê·¥"µÄ»°£¬ÎÒÏòÄãµÀǸ£¬Ï£ÍûÄã²» ÒªÒòΪÕâ¸öÔÒòÍ˶©¡£ >Õâ¸öÓʼþÁбíÊǹúÄÚÎÒ×îϲ»¶µÄ¼¼ÊõÉçÇøÖ®Ò»£¬ÎÒÏ£ÍûÄÜÒ»Ö±±£³ÖÁ¼ºÃµÄ½»Á÷Æø·Õ¡£ > >On 7/10/06, Xiao Lei Wu <xiaoleiw at cn.ibm.com> wrote: > > > > OK£¬ÎÒÏ£Íûµ½´ËΪֹ£¬ÎÒ²»ËµÁË£¬ÎÒÍ˶©£¬ÎÒ·¢ÏÖÕâÀïÒ²Óкܶà¿ñÈÈÕߣ¬Ò»¹É¹É ÎĸïÆøÏ¢ > > ±¾À´ÔÌÖÂÛÖ÷ÌâÊÇÊý¾Ý¿âÉè¼Æ£¬ÎÒÖ»ÊǾÙÀýÉÌÒµÁìÓòÊý¾Ý¿âÉè¼ÆµÄһЩ·ÖÆ磬˳±ã ´ø³öMySQLµÄһЩ²»×ã > > ÎÒʲôʱºò˵¹ý"MySQLÓ¦¸ÃÏûʧ"£¿Òì»ò"Ó¦¸Ã·ÅÆú"Ö®ÀàµÄ»°£¿ > > ÔõôÕâÀïÒ²ÏñijЩLinuxÂÛ̳һÑù£¬µ«·²Ë˵һ¾äLinux²»ºÃ£¬»òÕßMySQL²»ºÃÖ®Àà µÄ»°£¬¾ÍÒªÉϸÙÉÏÏß¿ÚÖï±Ê·¥£¿¾ÍÓÐÈËÒª±©ÌøÈçÀ×£¿ > > ¸üºÎ¿öÎÒ˵µÄ¶¼ÊÇÊÂʵ£¬ÎÒÖ»ÊÇÖ¸³öMySQLµÄÓ¦ÓÃÏÞÖƺÍËûµÄһЩ²»×㣬ÎÒÓÖûÓÐ ·´¶ÔËû£¬¸üû×çÖäËü°Ë°Ù±²×æ×Ú£¡ > > > > ÎÒÍƼö¶ÔÉÌÒµÓ¦ÓÃÓÐÐËȤµÄÈËÁ˽âÒ»ÏÂCompiereºÍPostgresql£¬£¨Äã²»¸ÐÐËȤ¿ÉÒÔ ²»Óùܣ¬ÄÇҲû±ØÒª¸úÕâ¸öÖ÷Ì⣩ÕâЩҲ¶¼ÊÇ¿ªÔ´Èí¼þÂ²Èµ½Ëβ°ÍÁË£¿ > > > > >-------------- next part -------------- >An HTML attachment was scrubbed... >URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060710/8a370a83/attachment.htm > >------------------------------ > >Message: 3 >Date: Mon, 10 Jul 2006 17:23:25 +0800 >From: Xiao Lei Wu <xiaoleiw at cn.ibm.com> >Subject: Re: [python-chinese] [django] ????? ?????? >To: python-chinese at lists.python.cn >Message-ID: > <OF1555B7E2.475F1263-ON482571A7.003379BE-482571A7.00335C93 at cn.ibm.com> >Content-Type: text/plain; charset="gb2312" > >²»ÊÇ˵Ä㣬²»ÒªÎó»á > >Best Regards, > >Zachary Wu (Îâ°~ÀÚ) >Software Engineer, Enterprise Content Management FVT, IBM China Software >Development Lab >Tel: +86 10 82782244-3235. Fax: 82782244-2886 Tie Line: 915-2244-3235 >Internet: xiaoleiw at cn.ibm.com >Notes ID: Xiao Lei Wu/China/Contr/IBM at IBMCN >Address: 8/F, Block A, Power Creative Building, No.1, East Road, Shang Di, >Beijing 100085, P.R. China > >python-chinese-bounces at lists.python.cn дÓÚ 2006-07-10 17:01:32: > > > ÎÒÓÃMySQLµÄʱºò»¹²»ÈçÓÃPostgreSQLµÄʱºò¶àÄØ£¬ÓÐʲôºÃ¿ñÈȵÄ... > > "MySQL²»ÊʺÏÆóÒµ¼¶Ó¦ÓÃ"ÕâÒ»µãÎÒÒ²ºÜÔÞͬÄ㣬µ«"MySQLÊÇÍæ¾ß"ºÍ"MySQL³Ð > > µ£²»ÁËÉÌÒµÒµÎñÂß¼"ÊÇÎÒ²»ÈÏͬµÄ¡£ > > ÎÒÖ»ÊÇÏ£ÍûÔÚÓʼþÁбíÖо¡Á¿´«´ïÕýÈ·È«ÃæµÄÐÅÏ¢£¬±ÈÈç"MySQL²»Ö§³ÖÊÂÎñºÍ > > Ëø"¾ÍºÜÃ÷ÏÔÊÇ»á¸ø±ðÈËÒÔÎóµ¼µÄÐÅÏ¢£¬¡ª¡ªµ±È»Èç¹ûÎÒʲôµØ·½Îóµ¼Á˱ðÈËÄÇ > > ôÇ뾡Á¿²ÈÎÒ²»Òª¿ÍÆø£¬ÎÒÒ»ÏòÈÏΪÔÚÌÖÂÛÖвÈÓë±»²ÈÊÇ¿ªÍØÑÛ½çµÄºÃ°ì·¨¡£ > > > > Anyway£¬Èç¹ûÎÒµÄÑÔ´ÊÈÃÄã¾õµÃÊÇ"ÉϸÙÉÏÏß¿ÚÖï±Ê·¥"µÄ»°£¬ÎÒÏòÄãµÀǸ£¬Ï£ > > ÍûÄã²»ÒªÒòΪÕâ¸öÔÒòÍ˶©¡£ > > Õâ¸öÓʼþÁбíÊǹúÄÚÎÒ×îϲ»¶µÄ¼¼ÊõÉçÇøÖ®Ò»£¬ÎÒÏ£ÍûÄÜÒ»Ö±±£³ÖÁ¼ºÃµÄ½»Á÷Æø >·Õ¡£ > > > On 7/10/06, Xiao Lei Wu <xiaoleiw at cn.ibm.com> wrote: > > OK£¬ÎÒÏ£Íûµ½´ËΪֹ£¬ÎÒ²»ËµÁË£¬ÎÒÍ˶©£¬ÎÒ·¢ÏÖÕâÀïÒ²Óкܶà¿ñÈÈÕߣ¬Ò»¹É¹ÉÎÄ >¸ïÆøÏ¢ > > ±¾À´ÔÌÖÂÛÖ÷ÌâÊÇÊý¾Ý¿âÉè¼Æ£¬ÎÒÖ»ÊǾÙÀýÉÌÒµÁìÓòÊý¾Ý¿âÉè¼ÆµÄһЩ·ÖÆ磬 > > ˳±ã´ø³öMySQLµÄһЩ²»×ã > > ÎÒʲôʱºò˵¹ý"MySQLÓ¦¸ÃÏûʧ"£¿Òì»ò"Ó¦¸Ã·ÅÆú"Ö®ÀàµÄ»°£¿ > > ÔõôÕâÀïÒ²ÏñijЩLinuxÂÛ̳һÑù£¬µ«·²Ë˵һ¾äLinux²»ºÃ£¬»òÕßMySQL²»ºÃÖ® > > ÀàµÄ»°£¬¾ÍÒªÉϸÙÉÏÏß¿ÚÖï±Ê·¥£¿¾ÍÓÐÈËÒª±©ÌøÈçÀ×£¿ > > ¸üºÎ¿öÎÒ˵µÄ¶¼ÊÇÊÂʵ£¬ÎÒÖ»ÊÇÖ¸³öMySQLµÄÓ¦ÓÃÏÞÖƺÍËûµÄһЩ²»×㣬ÎÒÓÖû > > Óз´¶ÔËû£¬¸üû×çÖäËü°Ë°Ù±²×æ×Ú£¡ > > ÎÒÍƼö¶ÔÉÌÒµÓ¦ÓÃÓÐÐËȤµÄÈËÁ˽âÒ»ÏÂCompiereºÍPostgresql£¬£¨Äã²»¸ÐÐËȤ > > ¿ÉÒÔ²»Óùܣ¬ÄÇҲû±ØÒª¸úÕâ¸öÖ÷Ì⣩ÕâЩҲ¶¼ÊÇ¿ªÔ´Èí¼þÂ²Èµ½Ëβ°ÍÁË£¿ > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese at lists.python.cn > > Subscribe: send subscribe to python-chinese-request at lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese >-------------- next part -------------- >An HTML attachment was scrubbed... >URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060710/e87b5a68/attachment.html > >------------------------------ > >Message: 4 >Date: Mon, 10 Jul 2006 02:36:24 -0700 >From: linda.s <samrobertsmith at gmail.com> >Subject: [python-chinese] balance2?? >To: python-chinese at lists.python.cn >Message-ID: > <1d987df30607100236x57807b0bje63f0f8d81c5b68 at mail.gmail.com> >Content-Type: text/plain; charset=GB2312; format=flowed > >ÓÃÈçÏ´úÂë, > >>> t7=BinaryTree(1) > >>> t7.addNode(2) > >>> t7.addNode(3) >Ò»Ö±µ½100,»áÊÇÒ»ÌõºÜ³¤µÄÊ÷,ÓÐʲô°ì·¨balanceÂð? > >class BinaryTree: > > def __init__(self, key, left=None, right=None, parent=None): > self.key = key > self.left = left > self.right = right > self.parent = parent > > def __str__(self): > return str(self.left) > return str(self.key) > > def addNode(self,key): > """Add a node in the proper location.""" > if key < self.key: > if self.left: > self.left.addNode(key) > else: > self.left = BinaryTree(key, parent=self) > elif key > self.key: > if self.right: > self.right.addNode(key) > else: > self.right = BinaryTree(key, parent=self) > >------------------------------ > >Message: 5 >Date: Mon, 10 Jul 2006 17:40:58 +0800 >From: "netkiller" <openunix at 163.com> >Subject: Re: [python-chinese] balance2?? >To: <python-chinese at lists.python.cn> >Message-ID: <000e01c6a404$f430ef70$3101320a at achievo.com> >Content-Type: text/plain; format=flowed; charset="gb2312"; > reply-type=original > > >ûÓÐʵÏÖÊ÷²éÕÒ¹¦ÄÜ£® > >----- Original Message ----- >From: "linda.s" <samrobertsmith at gmail.com> >To: <python-chinese at lists.python.cn> >Sent: Monday, July 10, 2006 5:36 PM >Subject: [python-chinese] balance2²æÊ÷ > > > > ÓÃÈçÏ´úÂë, > >>>> t7=BinaryTree(1) > >>>> t7.addNode(2) > >>>> t7.addNode(3) > > Ò»Ö±µ½100,»áÊÇÒ»ÌõºÜ³¤µÄÊ÷,ÓÐʲô°ì·¨balanceÂð? > > > > class BinaryTree: > > > > def __init__(self, key, left=None, right=None, parent=None): > > self.key = key > > self.left = left > > self.right = right > > self.parent = parent > > > > def __str__(self): > > return str(self.left) > > return str(self.key) > > > > def addNode(self,key): > > """Add a node in the proper location.""" > > if key < self.key: > > if self.left: > > self.left.addNode(key) > > else: > > self.left = BinaryTree(key, parent=self) > > elif key > self.key: > > if self.right: > > self.right.addNode(key) > > else: > > self.right = BinaryTree(key, parent=self) > > > > >-------------------------------------------------------------------------------- > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese at lists.python.cn > > Subscribe: send subscribe to python-chinese-request at lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > >------------------------------ > >_______________________________________________ >python-chinese mailing list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese > >End of python-chinese Digest, Vol 31, Issue 72 >********************************************** _________________________________________________________________ ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger: http://messenger.msn.com/cn
2006年07月10日 星期一 18:31
那要怎么做呢?下面的代码行吗? def find(self, key, flag=None): """Find a node. """ if self.key == key: return 1 elif key < self.key: if self.left: return self.left.find(key) else: return 0 elif key > self.key: if self.right: return self.right.find(key) else: return 0 On 7/10/06, netkiller <openunix at 163.com> wrote: > > 没有实现树查找功能. > > ----- Original Message ----- > From: "linda.s" <samrobertsmith at gmail.com> > To: <python-chinese at lists.python.cn> > Sent: Monday, July 10, 2006 5:36 PM > Subject: [python-chinese] balance2叉树 > > > > 用如下代码, > >>>> t7=BinaryTree(1) > >>>> t7.addNode(2) > >>>> t7.addNode(3) > > 一直到100,会是一条很长的树,有什么办法balance吗? > > > > class BinaryTree: > > > > def __init__(self, key, left=None, right=None, parent=None): > > self.key = key > > self.left = left > > self.right = right > > self.parent = parent > > > > def __str__(self): > > return str(self.left) > > return str(self.key) > > > > def addNode(self,key): > > """Add a node in the proper location.""" > > if key < self.key: > > if self.left: > > self.left.addNode(key) > > else: > > self.left = BinaryTree(key, parent=self) > > elif key > self.key: > > if self.right: > > self.right.addNode(key) > > else: > > self.right = BinaryTree(key, parent=self) > > > > > -------------------------------------------------------------------------------- > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese at lists.python.cn > > Subscribe: send subscribe to python-chinese-request at lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese >
2006年07月10日 星期一 20:29
DQpWZXJzaW9usrvGpcXk1OyzybXEDQoNCi0tLS0t08q8/tStvP4tLS0tLQ0Kt6K8/sjLOiBweXRo b24tY2hpbmVzZS1ib3VuY2VzQGxpc3RzLnB5dGhvbi5jbg0KW21haWx0bzpweXRob24tY2hpbmVz ZS1ib3VuY2VzQGxpc3RzLnB5dGhvbi5jbl0gtPqx7SBsaXUgemhpamllDQq3osvNyrG85DogMjAw NsTqN9TCMTDI1SAxNzo0NQ0KytW8/sjLOiBweXRob24tY2hpbmVzZUBsaXN0cy5weXRob24uY24N Ctb3zOI6IFtweXRob24tY2hpbmVzZV0gUkU6IHB5dGhvbi1jaGluZXNlIERpZ2VzdCwgVm9sIDMx LCBJc3N1ZSA3Mg0KDQoNCsq508NweXRob24yLjQgYXBhY2hlMiBtb2RfcHl0aG9uLTMuMi41Yi53 aW4zMi1weTIuNA0Kysdmcm9tIG1vZF9weXRob24gaW1wb3J0ICogyrGjrLP2z9bS1M/CtO3O8w0K RmlsZSAiQzpcUHl0aG9uXGxpYlxzaXRlLXBhY2thZ2VzXG1vZF9weXRob25cYXBhY2hlLnB5Iiwg bGluZSAzMSwgaW4gPw0KICAgIGltcG9ydCBfYXBhY2hlDQpJbXBvcnRFcnJvcjogTm8gbW9kdWxl IG5hbWVkIF9hcGFjaGUNCtPQxMTOu9DWtdzWqrXAysfKssO01K3S8rChDQrH69a4teOjrLK7yqS4 0LyksKGjoQ0KDQoNCj5Gcm9tOiBweXRob24tY2hpbmVzZS1yZXF1ZXN0QGxpc3RzLnB5dGhvbi5j bg0KPlJlcGx5LVRvOiBweXRob24tY2hpbmVzZUBsaXN0cy5weXRob24uY24NCj5UbzogcHl0aG9u LWNoaW5lc2VAbGlzdHMucHl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fX19fX19fX19fX19f X19fX19fX19fXw0KPiA+IHB5dGhvbi1jaGluZXNlDQo+ID4gUG9zdDogc2VuZCBweXRob24tY2hp bmVzZUBsaXN0cy5weXRob24uY24NCj4gPiBTdWJzY3JpYmU6IHNlbmQgc3Vic2NyaWJlIHRvIHB5 dGhvbi1jaGluZXNlLXJlcXVlc3RAbGlzdHMucHl0aG9uLmNuDQo+ID4gVW5zdWJzY3JpYmU6IHNl bmQgdW5zdWJzY3JpYmUgdG8gIA0KcHl0aG9uLWNoaW5lc2UtcmVxdWVzdEBsaXN0cy5weXRob24u Y24NCj4gPiBEZXRhaWwgSW5mbzogaHR0cDovL3B5dGhvbi5jbi9tYWlsbWFuL2xpc3RpbmZvL3B5 dGhvbi1jaGluZXNlDQo+DQo+DQo+DQo+DQo+DQo+LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tDQo+DQo+X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18N Cj5weXRob24tY2hpbmVzZSBtYWlsaW5nIGxpc3QNCj5weXRob24tY2hpbmVzZUBsaXN0cy5weXRo b24uY24NCj5odHRwOi8vcHl0aG9uLmNuL21haWxtYW4vbGlzdGluZm8vcHl0aG9uLWNoaW5lc2UN Cj4NCj5FbmQgb2YgcHl0aG9uLWNoaW5lc2UgRGlnZXN0LCBWb2wgMzEsIElzc3VlIDcyDQo+Kioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KDQpfX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXw0K 0+vBqrv6tcTF89PRvfjQ0L27wfejrMfryrnTwyBNU04gTWVzc2VuZ2VyOiAgaHR0cDovL21lc3Nl bmdlci5tc24uY29tL2NuICANCg0KX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX18NCnB5dGhvbi1jaGluZXNlDQpQb3N0OiBzZW5kIHB5dGhvbi1jaGluZXNlQGxp c3RzLnB5dGhvbi5jbg0KU3Vic2NyaWJlOiBzZW5kIHN1YnNjcmliZSB0byBweXRob24tY2hpbmVz ZS1yZXF1ZXN0QGxpc3RzLnB5dGhvbi5jbg0KVW5zdWJzY3JpYmU6IHNlbmQgdW5zdWJzY3JpYmUg dG8gIHB5dGhvbi1jaGluZXNlLXJlcXVlc3RAbGlzdHMucHl0aG9uLmNuDQpEZXRhaWwgSW5mbzog aHR0cDovL3B5dGhvbi5jbi9tYWlsbWFuL2xpc3RpbmZvL3B5dGhvbi1jaGluZXNlDQoNCi0tIA0K Tm8gdmlydXMgZm91bmQgaW4gdGhpcyBpbmNvbWluZyBtZXNzYWdlLg0KQ2hlY2tlZCBieSBBVkcg RnJlZSBFZGl0aW9uLg0KVmVyc2lvbjogNy4xLjM5NCAvIFZpcnVzIERhdGFiYXNlOiAyNjguOS4x MC8zODMgLSBSZWxlYXNlIERhdGU6IDIwMDYtNy03DQogDQoNCi0tIA0KTm8gdmlydXMgZm91bmQg aW4gdGhpcyBvdXRnb2luZyBtZXNzYWdlLg0KQ2hlY2tlZCBieSBBVkcgRnJlZSBFZGl0aW9uLg0K VmVyc2lvbjogNy4xLjM5NCAvIFZpcnVzIERhdGFiYXNlOiAyNjguOS4xMC8zODMgLSBSZWxlYXNl IERhdGU6IDIwMDYtNy03DQogDQo=
2006年07月10日 星期一 20:30
你很聪明, 你发现了 普通 2 叉查找树的缺点, 而且想寻找一种新的 算法 形成新的数据结构 来克服 这个缺点, 并且 将这种 新的数据结构 起了名字叫 *balance2叉树 *这跟科学家给的名字 几乎一样(balanced binary search tree) 有几种数据结构 如 AVL-tree RB-tree AA-tree 都可以实现 平衡二叉搜索树, 一般的 《数据结构》 书中都有介绍, 你可以 自己想一想, 编码试试 插入节点时 怎样 移动 节点 保持树的平衡, 然后再看看书, 看书上怎么是实现的。 On 7/10/06, linda. s <samrobertsmith at gmail.com> wrote: > > 那要怎么做呢?下面的代码行吗? > def find(self, key, flag=None): > """Find a node. > > """ > if self.key == key: > return 1 > elif key < self.key: > if self.left: > return self.left.find(key) > else: > return 0 > elif key > self.key: > if self.right: > return self.right.find(key) > else: > return 0 > On 7/10/06, netkiller < openunix at 163.com> wrote: > > > > 没有实现树查找功能. > > > > ----- Original Message ----- > > From: "linda.s" <samrobertsmith at gmail.com> > > To: < python-chinese at lists.python.cn> > > Sent: Monday, July 10, 2006 5:36 PM > > Subject: [python-chinese] balance2叉树 > > > > > > > 用如下代码, > > >>>> t7=BinaryTree(1) > > >>>> t7.addNode(2) > > >>>> t7.addNode(3) > > > 一直到100,会是一条很长的树,有什么办法balance吗? > > > > > > class BinaryTree: > > > > > > def __init__(self, key, left=None, right=None, parent=None): > > > self.key = key > > > self.left = left > > > self.right = right > > > self.parent = parent > > > > > > def __str__(self): > > > return str( self.left) > > > return str(self.key) > > > > > > def addNode(self,key): > > > """Add a node in the proper location.""" > > > if key < self.key: > > > if self.left: > > > self.left.addNode(key) > > > else: > > > self.left = BinaryTree(key, parent=self) > > > elif key > self.key: > > > if self.right: > > > self.right.addNode(key) > > > else: > > > self.right = BinaryTree(key, parent=self) > > > > > > > > > > -------------------------------------------------------------------------------- > > > > > > > _______________________________________________ > > > python-chinese > > > Post: send python-chinese at lists.python.cn > > > Subscribe: send subscribe to python-chinese-request at lists.python.cn > > > Unsubscribe: send unsubscribe to > python-chinese-request at lists.python.cn > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese at lists.python.cn > > Subscribe: send subscribe to python-chinese-request at lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060710/a69f29ad/attachment-0001.htm
Zeuux © 2025
京ICP备05028076号