本文整理汇总了C++中MinStack::min方法的典型用法代码示例。如果您正苦于以下问题:C++ MinStack::min方法的具体用法?C++ MinStack::min怎么用?C++ MinStack::min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MinStack
的用法示例。
在下文中一共展示了MinStack::min方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
int size = 10, pv, mv; MinStack<int> ms;
for (int i = 0; i < size; ++i) {
ms.push(pv = rand() % 100);
ms.min(mv); printf("push %d, min: %d\n", pv, mv);
}
while (ms.pop(pv)) { ms.min(mv); printf("pop %d, min: %d\n", pv, mv); }
return 0;
}
示例2: main
int main(int argc, char *argv[])
{
MinStack ms;
int r;
ms.push(1);
r = ms.pop();
assert(r == 1);
ms.push(2);
ms.push(3);
r = ms.min();
assert(r == 2);
ms.push(1);
r = ms.min();
assert(r == 1);
return 0;
}
示例3: main
int main()
{
MinStack<int> ms;
vector<int> a = {3,2,4,5,1};
for(size_t i=0; i < a.size(); ++i )
{
ms.push(a[i]);
cout << "push " << a[i] << endl;
cout << "min " << ms.min() << endl;
}
return 0;
}
示例4: main
int main() {
MinStack ms;
ms.push(7);
cout << ms.min();
ms.push(5);
cout << ms.min();
ms.push(9);
cout << ms.min();
ms.push(4);
cout << ms.min();
ms.push(2);
cout << ms.min();
ms.push(1);
cout << ms.min();
ms.pop();
ms.pop();
cout << ms.min();
return 0;
}
示例5: 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;
}