mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 225.cpp
This commit is contained in:
parent
675f0145ec
commit
68c35fb868
32
LeetCode-CN/225.cpp
Normal file
32
LeetCode-CN/225.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include <list>
|
||||||
|
class MyStack {
|
||||||
|
public:
|
||||||
|
/** Initialize your data structure here. */
|
||||||
|
MyStack() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Push element x onto stack. */
|
||||||
|
void push(int x) {
|
||||||
|
lst.push_back(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes the element on top of the stack and returns that element. */
|
||||||
|
int pop() {
|
||||||
|
int t = lst.back();
|
||||||
|
lst.pop_back();
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the top element. */
|
||||||
|
int top() {
|
||||||
|
return lst.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns whether the stack is empty. */
|
||||||
|
bool empty() {
|
||||||
|
return lst.empty();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::list<int> lst;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user