發表文章

目前顯示的是 6月, 2017的文章

觀察者模式

觀察者模式( Observer Pattern ) oo 設計 可以練習 封裝 繼承 多形 這裡以報社 和 客戶為例子 分別繼承 主題和觀察者 本文參考 : https://dotblogs.com.tw/joysdw12/archive/2013/03/13/96531.aspx 並轉為 python class Isubject(object):     def __init__(self):         self.IObserver = IObserver()         RegisterObserver(IObserver) class IObserver(object):     def __init__(self, name):         self.name = name     def Update(self, pMessage):         self.pMessage = pMessage class NewspaperOffice(Isubject):     def __init__(self):         self.List = []         self.pObserver = IObserver(self)     def RegisterObserver(self, pObserver):         self.List.append(pObserver)     def R...

MergeSort and QuickSort

圖片
MergeSort: Like   QuickSort , Merge Sort is a   Divide and Conquer   algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves http://www.geeksforgeeks.org/merge-sort/ QuickSort: Quicksort is a  divide and conquer algorithm . Quicksort first divides a large array into two smaller sub-arrays: the low elements and the high elements. Quicksort can then recursively sort the sub-arrays. The steps are: Pick an element, called a  pivot , from the array. Partitioning : reorder the array so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the  partition  operation. Recursively  apply the above steps to the sub-array of elements with smaller values and separately to th...