-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathW9_P4.cpp
77 lines (66 loc) · 967 Bytes
/
W9_P4.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <vector>
using namespace std;
class PriorityQueue {
private:
vector<int>v;
public:
bool empty() {
if (v.size() == 0) {
return 1;
}
return 0;
}
void push(int e) {
if (empty()) {
v.push_back(e);
}
else {
for (auto i = v.begin(); i != v.end(); i++) {
if (e > *i) {
v.insert(i, e);
return;
}
}
v.insert(v.end(), e);
}
}
int pop() {
if (!empty()) {
int value = v.front();
v.erase(v.begin());
return value;
}
else
{
return 0;
}
}
};
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> v;
PriorityQueue pq;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
v.push_back(num);
}
for (int i = 0; i < n; i++) {
pq.push(v.front());
v.erase(v.begin());
}
for (int i = 0; i < n; i++) {
v.push_back(pq.pop());
}
for (int i = 0; i < n; i++) {
cout << v[i] << " ";
}
cout << "\n";
}
return 0;
}