![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法与数据结构
文章平均质量分 60
vczhfan
这个作者很懒,什么都没留下…
展开
-
clrs chp6
优先队列的实现原创 2014-07-16 09:25:53 · 330 阅读 · 0 评论 -
1005
#include#include#include#includeusing namespace std;int main(){ freopen("in.txt","r",stdin); map cache; int t; cin>>t; while(t--){ int x; cin>>x; while(x!=1){ cache[x]++; if(x&0原创 2014-07-10 22:06:37 · 339 阅读 · 0 评论 -
python list的实现
#include#includeusing namespace std;const int InitCapacity=100;class List{private: int *arr; int capacity; int size; void quicksort(int *arr,int left,int right){ if(right-left>1){ int i,原创 2014-07-12 16:46:01 · 335 阅读 · 0 评论 -
逆序对的nlgn算法
def inversion(A,p,r): #inversion return inversion num and sort the arr if(r-p<=1): return 0 else: q=(p+r)//2 n1,n2=inversion(A,p,q),inversion(A,q,r) n3=0 L=A[p:q原创 2014-07-13 16:45:01 · 808 阅读 · 0 评论 -
1006
#include#include#includeusing namespace std;int main(){ freopen("in.txt","r",stdin); int n; cin>>n; int b,s,g; b=n/100,s=(n-b*100)/10,g=n%10; while(b--) cout<<"B"; while(s--) cout<<"S"; f原创 2014-07-11 10:32:40 · 291 阅读 · 0 评论 -
简单scheme计算器-python实现
class nil(object): """The empty list""" def __len__(self): return 0 def map(self,fn): return self def __repr__(self): return 'nil'nil=nil() # nil now refers to原创 2014-07-14 20:08:45 · 501 阅读 · 0 评论 -
用python实现二项树
class Tree: def __init__(self,entry,left=None,right=None): self.entry=entry self.left=left self.right=right def __repr__(self): args=repr(self.entry) if原创 2014-07-14 18:29:46 · 510 阅读 · 0 评论 -
寻找第f小数的证明
在数列A[1...N] 中查找第k小的数算法如下:1任意选定一个数r原创 2014-07-15 00:31:16 · 310 阅读 · 0 评论 -
hw7
class Tree: def __init__(self,entry,left=None,right=None): self.entry=entry self.left=left self.right=right def __repr__(self): args=repr(self.entry) if原创 2014-07-14 18:47:32 · 488 阅读 · 0 评论 -
quicksort in clrs
def quick_sort(A,p,r): if p<r: q=partition(A,p,r) quick_sort(A,p,q-1) quick_sort(A,q+1,r)def partition(A,p,r): x=A[r] i=p-1 for j in range(p,r): if A[j原创 2014-07-16 08:26:37 · 261 阅读 · 0 评论 -
list 的c实现
typedef struct Nameval Nameval;struct Nameval{ char *name; int value; Nameval *next;};Nameval *newitem(char *name,int value){ Nameval *newp; newp=(Nameval*)malloc(sizeof(Nameval)); newp->nam原创 2014-07-20 22:47:41 · 434 阅读 · 0 评论 -
chap11 stack
class Stack: initial_capacity=10 def __init__(self): self.A=[0]*self.initial_capacity self.top=0 self.capacity=self.initial_capacity def expand(self): self.原创 2014-07-16 10:38:58 · 273 阅读 · 0 评论 -
chap10-queue
class Queue: initial_capacity=10 def __init__(self): self.A=[0]*self.initial_capacity self.capacity=self.initial_capacity self.head=0 self.tail=0 def __repr原创 2014-07-16 11:16:04 · 303 阅读 · 0 评论 -
chap10-DLinkList
class Node: def __init__(self,key,prev=None,next=None): self.key=key self.prev=prev self.next=nextclass List: def __init__(self): self.nil=Node('error')原创 2014-07-16 13:18:07 · 349 阅读 · 0 评论 -
chap10 list 单链表实现
class Node: def __init__(self,key,next=None): self.key=key self.next=nextclass LinkList: def __init__(self): self.nil=Node('error',None) self.nil.next=self.nil原创 2014-07-16 15:17:36 · 288 阅读 · 0 评论 -
chap11 哈希表链接法
from functools import reducefrom operator import addfrom random import seed,randintclass Node: def __init__(self,key,prev=None,next=None): self.key,self.prev,self.next=key,prev,nextcla原创 2014-07-17 15:25:59 · 308 阅读 · 0 评论 -
chap11 哈希表实现-开放寻址法
from functools import reducefrom operator import addclass HashTable: size=97 def hash(k,i): return (reduce(add,map(ord,str(k)),0)+i)%HashTable.size def __init__(self): se原创 2014-07-17 15:51:17 · 912 阅读 · 0 评论 -
树的各类算法
class Tree: def __init__(self,key,left=None,right=None,par=None): self.key,self.left,self.right,self.par=key,left,right,pardef inorder(t): if t!=None: inorder(t.left)原创 2014-07-16 21:48:56 · 291 阅读 · 0 评论 -
实现有序列表和无序列表
class Node: def __init__(self,init_data): self.data=init_data self.next=None def get_data(self): return self.data def get_next(self): return self.next d原创 2014-07-17 23:31:47 · 554 阅读 · 0 评论 -
二分查找
def bsearch(a_list,item): first=0 last=len(a_list)-1 found=False while first<=last and not found: midpoint=(first+last)//2 if a_list[midpoint]==item: found=原创 2014-07-18 00:27:19 · 278 阅读 · 0 评论 -
python 哈希表实现
class HashTable: def __init__(self): self.size=11 self.slots=[None]*self.size self.data=[None]*self.size def hash_function(self,key,size): return key%size d原创 2014-07-18 00:56:27 · 970 阅读 · 0 评论 -
马尔可夫链文本处理
#include#include#include#include#includeusing namespace std;typedef deque Prefix;map > statetab;string NONWORD="\n";enum {MAXGEN=20,NPREF=2};void build(Prefix&,istream&);void add(Prefix&,co原创 2014-07-21 10:38:24 · 522 阅读 · 0 评论 -
heapsort
class heap: def __init__(self,A): self.A=A self.size=0 self.length=len(A)-1 def __setitem__(self,i,x): self.A[i]=x def __getitem__(self,i): return s原创 2014-07-16 08:55:39 · 274 阅读 · 0 评论