2013年4月9日
摘要: 定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素。要求函数min、push以及pop的时间复杂度都是O(1)。在栈中包含另一个记录在各元素压入堆栈之后的最小元素下标的数组就可以实现。 1 #include <iostream> 2 3 using namespace std; 4 5 //栈功能实现类 6 template<class T, int capacity> 7 class min_stack 8 { 9 private: 10 T m_data[capacity]; 11 int m_index[capacity];//保存栈中该... 阅读全文
posted @ 2013-04-09 15:58 blue firmament 阅读(140) 评论(0) 推荐(0) 编辑