摘要: 下面是使用Array实现Vector.也就是Python中自带的list().代码如下:class Vector: def __init__(self): self._length = 0 self._capacity = 2 self._array = Array(self._capacity) def __len__(self): return self._length def __contains__(self,item): for v in self: ... 阅读全文
posted @ 2012-11-29 22:02 zhuangzhuang1988 阅读(281) 评论(0) 推荐(0) 编辑
摘要: Array2D实现好之后就是要来做一个程序了.简单测程序 `生命游戏`,当然以前发过的,不过是使用SDL+C++写的.现在直接使用Python写,代码如下.这个主要是棋盘的设定.class LifeGrid: DEAD_CELL = 0 LIVE_CELL = 1 def __init__(self,numRows,numCols): self._grid = Array2D(numRows,numCols) self.configure(list()) def numRows(self): return... 阅读全文
posted @ 2012-11-29 17:02 zhuangzhuang1988 阅读(430) 评论(0) 推荐(0) 编辑
摘要: 今天就到了二维的了.Python中默认是没有带二维的数据结构的.二维的数据结构可以通过一维的数据组成.代码如下class Array2D: def __init__(self,numRows,numCols): self._theRows = Array(numRows) for i in range(numRows): self._theRows[i] = Array(numCols) def numRows(self): return len(self._theRows) ... 阅读全文
posted @ 2012-11-29 00:14 zhuangzhuang1988 阅读(369) 评论(0) 推荐(0) 编辑