原创 python-鏈表(無序鏈表、有序鏈表)
class Node: def __init__(self,initdata): self.data = initdata self.next = None def getData(se
原创 機器學習思維導圖(Machine Learning Mindmap)
一個總結機器學習概念的思維圖,從數據分析到深入學習。 https://github.com/dformoso/machine-learning-mindmap Overview 機器學習是計算機科學的一個子領域,使計算機不需要明確的編程步
原创 Python國內外在線參考材料
在線參考材料 數據結構與算法(基於 Python 語言)課程(北京大學數學學院) 在線教材:Problem Solving with Algorithms and Data Structures 許多 Python 學習材料,包括算法與數
原创 python-雙端隊列
from pythonds.basic.deque import Deque class Deque: def __init__(self): self.items = [] def isEmpty(s
原创 python-類
創建類 類(Class): 用來描述具有相同的屬性和方法的對象的集合。它定義了該集合中每個對象所共有的屬性和方法。對象是類的實例。 使用class語句來創建一個新類,class之後爲類的名稱並以冒號結尾,如下實例: class Clas
原创 python-查找樹
class BinarySearchTree: def __init__(self): self.root=None self.size=0 def length(self):
原创 python-隊列
from pythonds.basic.queue import Queue import random def hotPotato(namelist,num): simqueue = Queue() for name
原创 Python-樹
樹節點類 TreeNode 作爲最簡單的樹節點,我們只需要3個基本屬性 name: 當前節點的名字(使用str來保存) parent: 父節點對象(對根節點來說,該值爲Null) child: 字節點對象們(使用dict來保存) 代碼如下
原创 python-二叉堆
class BinHeap: def __init__(self): self.heapList = [0] self.currentSize = 0 def percUp(se
原创 python-棧
from pythonds.basic.stack import Stack def parChecker(symbolString): s=Stack() balanced=True index=0
原创 python-排序
def bubbleSort(alist): for passnum in range(len(alist)-1,0,-1): for i in range(passnum): if
原创 python-檢索
def sequentialSearch(alist,item): pos = 0 found = False while pos < len(alist) and not found: if a
原创 python-文件I/O與異常處理
open函數 Python內置的open()函數打開一個文件,創建一個file對象,相關的輔助方法纔可以調用它進行讀寫。語法爲: file object = open(file_name [, access_mode][, buffer
原创 python-圖(鄰接表)
class Vertex: def __init__(self,key): self.id=key self.connectedTo={} def addNeighbor(sel
原创 python-樹(樹的遍歷)
#列表表示樹 def BinaryTree(r): return [r, [], []] def insertLeft(root,newBranch): t = root.pop(1) if len(t) >