add: 230828
This commit is contained in:
parent
9860bb7a54
commit
7f8946ce7a
|
|
@ -0,0 +1,40 @@
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
class LC230828 {
|
||||||
|
private:
|
||||||
|
std::queue<int> q;
|
||||||
|
|
||||||
|
public:
|
||||||
|
LC230828();
|
||||||
|
void push(int x);
|
||||||
|
int pop();
|
||||||
|
int top();
|
||||||
|
bool empty();
|
||||||
|
};
|
||||||
|
|
||||||
|
LC230828::LC230828() = default;
|
||||||
|
|
||||||
|
void LC230828::push(int x) {
|
||||||
|
int n = q.size();
|
||||||
|
q.push(x);
|
||||||
|
while (n--) {
|
||||||
|
q.push(q.front());
|
||||||
|
q.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int LC230828::pop() {
|
||||||
|
int ret = q.front();
|
||||||
|
q.pop();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LC230828::top() {
|
||||||
|
return q.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LC230828::empty() {
|
||||||
|
return q.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef LEETCODE_CPP_DEFS_H
|
#ifndef LEETCODE_CPP_DEFS_H
|
||||||
#define LEETCODE_CPP_DEFS_H
|
#define LEETCODE_CPP_DEFS_H
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class LC230827 {
|
class LC230827 {
|
||||||
|
|
@ -8,4 +9,17 @@ public:
|
||||||
static bool canCross(const std::vector<int>&);
|
static bool canCross(const std::vector<int>&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LC230828 {
|
||||||
|
private:
|
||||||
|
std::queue<int> q;
|
||||||
|
|
||||||
|
public:
|
||||||
|
LC230828();
|
||||||
|
void push(int x);
|
||||||
|
int pop();
|
||||||
|
int top();
|
||||||
|
bool empty();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif //LEETCODE_CPP_DEFS_H
|
#endif //LEETCODE_CPP_DEFS_H
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue