当前位置: 首页>>代码示例>>C++>>正文


C++ MinStack类代码示例

本文整理汇总了C++中MinStack的典型用法代码示例。如果您正苦于以下问题:C++ MinStack类的具体用法?C++ MinStack怎么用?C++ MinStack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MinStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TEST_F

TEST_F(SolutionTest, case1) {
	MinStack mstack;
	for (int i = 100; i >= 0; i--) {
		mstack.push(i);
		EXPECT_EQ(mstack.getMin(), i);
		EXPECT_EQ(mstack.top(), i);
	}
	EXPECT_EQ(mstack.getMin(), 0);
	EXPECT_EQ(mstack.top(), 0);
	mstack.pop();
	EXPECT_EQ(mstack.getMin(), 1);
	EXPECT_EQ(mstack.top(), 1);
}
开发者ID:babypuma,项目名称:leetcode,代码行数:13,代码来源:min_stack_test.cpp

示例2: main

int main() {
	MinStack minStack;
	minStack.push(-2);
	minStack.push(0);
	minStack.push(-3);
	cout << minStack.getMin() <<  "--> Returns -3" << endl;
	minStack.pop();
	cout << minStack.top() << "--> Returns 0" << endl;
	cout << minStack.getMin() <<  "--> Returns -2" << endl;
}
开发者ID:eagle9,项目名称:palgo,代码行数:10,代码来源:shaun1.cpp

示例3: main

int main(){
    MinStack stack;
    stack.push(-2);
    stack.push(0);
    stack.push(-1);
    std::cout << stack.getMin() << std::endl;
    std::cout << stack.top() << std::endl;
    stack.pop();
    std::cout << stack.getMin() << std::endl;
    return 0;
}
开发者ID:lobalani,项目名称:algo,代码行数:11,代码来源:min-stack.cpp

示例4: TEST

TEST(leetcode_155_min_stack, Basic)
{
    MinStack *minStack = new MinStack();
    minStack->push(-2);
    minStack->push(0);
    minStack->push(-3);
    EXPECT_EQ(-3, minStack->getMin());
    minStack->pop();
    EXPECT_EQ(0, minStack->top());
    EXPECT_EQ(-2, minStack->getMin());
}
开发者ID:duxins,项目名称:leetcode,代码行数:11,代码来源:155-min-stack.cpp

示例5: main

int main(void)
{
	MinStack engine;
	engine.push(-2);
	engine.push(0);
	engine.push(-1);
	cout << engine.getMin() << '\n';
	cout << engine.top() << '\n';
	engine.pop();
	cout << engine.getMin() << '\n';
	return 0;
}
开发者ID:CaptainCan,项目名称:Leetcode,代码行数:12,代码来源:155+LL.cpp

示例6: main

int main()
{
  MinStack * myStack = new MinStack();
  myStack->push(5);
  myStack->push(2);
  myStack->push(6);
  myStack->push(10);
  myStack->push(-1);
  myStack->PrintQueue();
  myStack->PrintStack();
  printf("Popping !\n");
  myStack->pop();
  myStack->PrintQueue();
  myStack->PrintStack();
  return 0;
}
开发者ID:SirNyble,项目名称:LeetCode,代码行数:16,代码来源:main.cpp

示例7: main

int main() 
{
	MinStack minStack;
	minStack.push(-2);
	minStack.push(0);
	minStack.push(-3);
	cout << minStack.getMin() << endl; //   --> Returns -3.
	minStack.pop();
	cout << minStack.top() << endl;    //  --> Returns 0.
	cout << minStack.getMin() << endl; //   --> Returns -2.

    return 0;
}
开发者ID:sniperswang,项目名称:dev,代码行数:13,代码来源:test.cpp

示例8: main

int main()
{
        MinStack *st = new MinStack;
        int ch, data;
        while (1) {
                scanf("%d", &ch);
                if (ch == 1) {
                        scanf("%d", &data);
                        st->push(data);
                } else if (ch == 2) {
                        st->pop();
                } else if (ch == 3) {
                        printf("Head: %d\n", st->peek());
                } else if (ch == 4) {
                        printf("Min: %d\n", st->min());
                } else if (ch == 5) {
                        break;
                }
        }
        return 0;
}
开发者ID:RudraNilBasu,项目名称:C-CPP-Codes,代码行数:21,代码来源:3_2.cpp

示例9: main

int main(){
  MinStack stk;
  stk.push(3);
  stk.push(1);
  stk.push(8);
  int minS = stk.getMin();
  stk.push(7);
  stk.pop();
  stk.pop();
  stk.push(12);
  minS = stk.getMin();
  getchar();
  return 0;
}
开发者ID:JimberXin,项目名称:Leetcode,代码行数:14,代码来源:Min+Stack.cpp

示例10: main

int main () {
	MinStack st;
	st.push(2);st.push(0);st.push(3);
	st.push(1);
	cout << st.top() << endl;
	cout << st.getMin();
}
开发者ID:guohuiGH,项目名称:codes,代码行数:7,代码来源:155_min_stack.cpp

示例11: main

int main()
{
	MinStack stack;
	int oporation;
	int value;

	while(1)
	{
		cin >> oporation;
		switch(oporation)
		{
			case 0:
			{
				cin >> value;
				stack.push(value);
				break;
			}
			case 1:
			{
				stack.pop();
				break;
			}
			case 2:
			{
				value = stack.top();
				cout << "top = " << value << endl;
				break;
			}
			case 3:
			{
				value = stack.getMin();
				cout << "min = " << value << endl;
				break;
			}
		}
	}
	
	return 0;
}
开发者ID:oliverpei,项目名称:leetcode,代码行数:39,代码来源:stack.cpp

示例12: main

int main()
{
	MinStack minstack;

	minstack.push(3);
	minstack.pop();
	minstack.push(5);
	minstack.push(3);
	minstack.push(2);
	minstack.push(1);
	minstack.push(4);
	cout<<"minstack.top():"<<minstack.top()<<endl;
	cout<<"minstack.getMin():"<<minstack.getMin()<<endl;
	
	return 0;
}
开发者ID:ChiaYuLin,项目名称:Leetcode,代码行数:16,代码来源:MinStack_TimeLimitExceed.cpp

示例13: main

int main(int argc, char const *argv[]) {
    MinStack myStack;
    int n, k;
    cout << "input n: ";
    while (cin >> n && n != -1) {
        myStack.push(n);
        cout << "input n: ";
    }
    cout << "0 - nothing, 1 - pop(), 2 - top(), 3 - getMin()" << endl;
    while (cin >> k && k != -1) {
        switch (k) {
            case 1: myStack.pop(); break;
            case 2: cout << "top: " << myStack.top() << endl; break;
            case 3: cout << "min: " << myStack.getMin() << endl; break;
            case 0: cout << "no process." << endl; break;
        }
        cout << "0 - nothing, 1 - pop(), 2 - top(), 3 - getMin()" << endl;
    }
    // stack<int> s;
    // s.push(1);
    // s.pop();
    return 0;
}
开发者ID:CullenGao,项目名称:Leetcode,代码行数:23,代码来源:minStack.cpp

示例14: main

int main(){
	MinStack st;
	st.push(2);
	st.push(3);
	st.pop();
	st.push(1);
	st.push(6);
	st.pop();
	st.push(7);
	cout<<st.getMin()<<endl;

	system("pause");
}
开发者ID:hyfeng,项目名称:leetcode,代码行数:13,代码来源:min_stack.cpp

示例15: main

int main () {
    MinStack* obj = new MinStack();
    obj->push(0);
    obj->push(1);
    obj->push(0);
    obj->getMin();
    obj->pop();
    obj->getMin();
    return 0;
}
开发者ID:husterxsp,项目名称:leetcode,代码行数:10,代码来源:MinStack.cpp


注:本文中的MinStack类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。