06 2012 档案
摘要:1 #ifndef STACK_H 2 #define STACK_H 3 4 #include<stdexcept> 5 #include<string> 6 using namespace std; 7 8 template<typename T> 9 class Stack10 {11 private:12 template<typename T>13 struct Node14 {15 T data;16 Node* next;17 Node(T data,Node* next):data(data),nex...
阅读全文
摘要:写了一个单链表的模板,欢迎大家批评指正。 1 #ifndef LINKEDLIST_H 2 #define LINKEDLIST_H 3 #define DEBUG 4 5 #include<iostream> 6 using namespace std; 7 8 template <typename T> 9 class LinkedList 10 { 11 public: 12 template<typename T> 13 struct Node 14 { 15 T data; 16 Node* next; 1...
阅读全文
摘要:1 #ifndef FACTORYMETHOD_H 2 #define FACTORYMETHOD_H 3 4 #include<iostream> 5 using namespace std; 6 7 class Product//should be a pure virtual class. 8 { 9 public:10 Product(){}11 ~Product(){}12 };13 14 class ConcreteProductA:public Product15 {16 public:17 ConcreteProductA()18 {19 ...
阅读全文
摘要:装饰者模式(Decorator Pattern):动态地给一个对象添加一些额外的职责,就增加功能来说,装饰者模式比生成子类更加灵活。 1 #ifndef DECORATOR_H 2 #define DECORATOR_H 3 4 #include<iostream> 5 using namespace std; 6 7 class Component 8 { 9 public:10 virtual void operation()=0;11 };12 13 class ConcreteComponent:public Component14 {15 public:16 vo...
阅读全文
摘要:1 #ifndef OBSERVER_H 2 #define OBSERVER_H 3 #include<list> 4 #include<iostream> 5 using namespace std; 6 7 class Observer 8 { 9 public: 10 virtual void update()=0; 11 }; 12 13 class Subject 14 { 15 public: 16 virtual void attach(Observer* observer)=0; 17 virtual void detach(O...
阅读全文
摘要:1 #ifndef BSTREE_H 2 #define BSTREE_H 3 #include<cassert> 4 #include<stack> 5 using namespace std; 6 7 template<typename T> 8 class BSTree 9 { 10 public: 11 template<typename T> 12 struct Node{ 13 T data; 14 Node* lchild; 15 Node* rchild; 16 Node* p...
阅读全文
摘要:策略模式(Strategy):定义了算法家族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户。[DP]以下为策略模式的实现代码。 1 #include<iostream> 2 using namespace std; 3 4 class Strategy{ 5 public: 6 Strategy(void){} 7 virtual ~Strategy(void){} 8 9 virtual void AlgorithmInterface()=0;10 };11 12 class ConcreteStrategyA:public ...
阅读全文

浙公网安备 33010602011771号