-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion3.cpp
More file actions
53 lines (40 loc) · 839 Bytes
/
Question3.cpp
File metadata and controls
53 lines (40 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// Created by 张元一 on 11/02/2022.
//
#include <iostream>
#include <vector>
#include <mutex>
#include "Question3.h"
using std::initializer_list;
using std::array;
using std::mutex;
namespace mpcs51044 {
template<typename T>
class Stack{
public:
Stack() : data{} {}
Stack(initializer_list<T> init){
for (auto row : init){
data.push(row);
}
}
void push(T new_num){
std::lock_guard guard(m);
data.push(new_num);
}
T pop(){
std::lock_guard guard(m);
return data.pop();
}
private:
mutex m;
List<T> data;
};
}
int main(){
mpcs51044::Stack<int> s = {1,2,3};
std::cout << s.pop();
s.push(7);
s.push(5);
std::cout << s.pop();
}