摘要: 思路要清晰。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 阅读(293) 评论(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 阅读(206) 评论(0) 推荐(1) 编辑
摘要: 猴子分桃海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子平均分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,问海滩上原来最少有多少个桃子?View Code 1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int m=1; 7 while(1) 8 { 9 int n=m;10 int i;11 fo... 阅读全文
posted @ 2011-11-16 02:22 YipWingTim 阅读(218) 评论(0) 推荐(0) 编辑