随笔分类 -  Stack&Queue

摘要:思路要清晰。View Code 1 //两队列实现栈 2 #include<iostream> 3 using namespace std; 4 5 template<class Type> class Queue 6 { 7 private: 8 int rear,front; 9 Type* elements; 10 int maxSize; 11 public: 12 Queue(int sz=50):rear(0),front(0),maxSize(sz) 13 { 14 elements=new Type[... 阅读全文
posted @ 2011-11-16 05:04 YipWingTim 阅读(309) 评论(0) 推荐(0)
摘要:比较简单。View Code 1 //用两个栈实现队列 2 3 #include<iostream> 4 using namespace std; 5 6 template<class Type> class Stack 7 { 8 private: 9 int top;10 Type* elements;11 int maxSize;12 public:13 Stack(int sz=50):top(-1),maxSize(sz)14 {15 elements=new Type[sz];16 }17 18 void... 阅读全文
posted @ 2011-11-16 03:19 YipWingTim 阅读(215) 评论(0) 推荐(1)
摘要:代码比较简单,测试都懒得了,这个问题思想是精华。View Code 1 #include<iostream> 2 using namespace std; 3 4 class Stack 5 { 6 private: 7 int *elements; 8 int top; 9 int maxSize; 10 11 public: 12 Stack(int sz=50):top(-1),maxSize(sz) 13 { 14 elements=new int[maxSize]; 15 } 16 17 ... 阅读全文
posted @ 2011-11-15 19:25 YipWingTim 阅读(356) 评论(0) 推荐(0)
摘要:哈哈。只考虑了两个小时左右,我已经深的递归精髓了,哈哈。递归解决问题真的是太容易了,归纳演绎完全诠释了数学的精妙,哈,这个世界好得很。。。。重复感叹一句,迭代的是人,递归的是神。。。。分析时间复杂度,公式为f(n)=2*f(n-1)+f(n-2),可以用递归求出通项,初略估计为3^n。View Code 1 #include<iostream> 2 using namespace std; 3 4 class Stack 5 { 6 private: 7 int* elements; 8 int top; 9 int maxSize;10 public:11 ... 阅读全文
posted @ 2011-11-15 02:10 YipWingTim 阅读(923) 评论(0) 推荐(0)