Skip to content

Commit 2ed3f9c

Browse files
committed
重构队列类,修复前端访问错误并添加空检查
1 parent 3bee31d commit 2ed3f9c

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

  • niuke/practice/noob/noob93 【模板】队列操作

niuke/practice/noob/noob93 【模板】队列操作/1.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,49 @@
33
#include <vector>
44
using namespace std;
55

6+
template <typename T>
7+
class Queue_e{
68

9+
queue<T> q;
10+
public:
711

8-
template
12+
void push(const T& x){
13+
q.push(x);
14+
}
15+
16+
void pop(){
17+
if(!q.empty()){
18+
q.pop();
19+
}else{
20+
cout << "ERR_CANNOT_POP\n";
21+
}
22+
}
23+
24+
void front() const {
25+
if(!q.empty()){
26+
cout << q.fornt() << '\n';
27+
}else{
28+
cout << "ERR_CANNOT_QUERY\n";
29+
}
30+
}
31+
32+
void size() const {
33+
cout << q.size() << '\n';
34+
}
35+
36+
bool empty() const {
37+
return q.empty();
38+
}
39+
40+
};
941

1042
int main() {
11-
queue<int> q;
43+
Queue_e<int> qe;
1244
int n;cin>> n;
1345

46+
while(n--){
47+
48+
}
1449

1550
}
1651
// 64 位输出请用 printf("%lld")

0 commit comments

Comments
 (0)