本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
示例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;
}