原创 最大子數組

分治法def find_max_sum(A,low,high): if high==low: return low,high,A[low] else: mid=(low+high)//2

原创 python list的實現

#include<iostream> #include<cassert> using namespace std; const int InitCapacity=100; class List{ private: int *arr;

原创 212

#include<iostream> #include<cstdio> #include<algorithm> #include<vector> using namespace std; int main() { freopen(

原创 305

#include<iostream> #include<list> #include<cstdio> using namespace std; int main() { freopen("in.txt","r",stdin); in

原创 用python實現二項樹

class Tree: def __init__(self,entry,left=None,right=None): self.entry=entry self.left=left

原创 quicksort in clrs

<pre name="code" class="python">def quick_sort(A,p,r): if p<r: q=partition(A,p,r) quick_sort(A,p,q-

原创 304

#include<iostream> #include<cstdio> #include<algorithm> #include<vector> #include<map> #include<functional> using names

原创 1010

#include<iostream> #include<vector> #include<string> using namespace std; int main() { freopen("in.txt","r",stdin); int

原创 chap5

def hire_assistant(A,n): best=0 for i in range(0,n): x=A[i] if A[i]>best: best=i

原创 逆序對的nlgn算法

<pre name="code" class="python">def inversion(A,p,r): #inversion return inversion num and sort the arr if(r-p<=1)

原创 求逆序對的nlgn算法

def inversion(A,p,r): #inversion return inversion num and sort the arr if(r-p<=1): return 0 else:

原创 尋找第f小數的證明

在數列A[1...N] 中查找第f小的數 算法如下: 1任意選定一個數r(比如說A[f]),然後將A[m...n]分成兩部分: A[m],...A[k],A[k+1],...A[n] 並滿足 A[m],...,A[k]<=r A[k+1]

原创 簡單scheme計算器-python實現

class nil(object): """The empty list""" def __len__(self): return 0 def map(self,fn): retur

原创 chap10 list 單鏈表實現

class Node: def __init__(self,key,next=None): self.key=key self.next=next class LinkList: def _

原创 python 哈希表實現

class HashTable: def __init__(self): self.size=11 self.slots=[None]*self.size self.data=[No