-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9-4.cpp
74 lines (65 loc) · 1.09 KB
/
9-4.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
#include <iostream>
#include <vector>
using namespace std;
class isLess {
public:
bool operator()(int a, int b) {
return a < b;
}
};
class NSPQ {
public:
vector<int>v;
int size() {
return v.size();
}
bool empty() {
return v.empty();
}
void insert(int data) {
v.push_back(data);
}
int min() {
int min = v.front();
vector<int>::iterator p = v.begin();
for (vector<int>::iterator i = v.begin(); i != v.end(); i++) {
if (min > *i) {
min = *i;
p = i;
}
}
return min;
}
void removemin() {
int min = v.front();
vector<int>::iterator p = v.begin();
for (vector<int>::iterator i = v.begin(); i != v.end(); i++) {
if (min > *i) {
min = *i;
p = i;
}
}
v.erase(p);
}
};
int main() {
int t, n, temp;
cin >> t;
while (t--) {
cin >> n;
vector<int> s;
NSPQ q;
for (int i = 0; i < n; i++) {
cin >> temp;
q.insert(temp);
}
for (int i = 0; i < n; i++) {
s.push_back(q.min());
q.removemin();
}
for (vector<int>::iterator iter = --s.end(); iter != s.begin(); --iter) {
cout << *iter << ' ';
}
cout << s.front() << endl;
}
}