-
Notifications
You must be signed in to change notification settings - Fork 0
/
2021_SortedSeqPQMax.cpp
70 lines (63 loc) · 1.21 KB
/
2021_SortedSeqPQMax.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
// Created by dongwan-kim on 2022/04/29.
#include<iostream>
#include<vector>
using namespace std;
class SortedSeqPQMax{
public:
vector<int>seq;
int size(){
return seq.size();
}
bool empty(){
return seq.size()==0;
}
void insert(int e){
int idx=0;
for(idx=0;idx<seq.size();idx++){
if(seq[idx]<e)
break;
}
seq.insert(seq.begin()+idx,e);
}
int max(){
if(empty())
return -1;
else{
return seq[0];
}
}
void removeMax(){
if(empty())
cout<<-1<<endl;
else{
seq.erase(seq.begin());
}
}
};
int main(){
int t;
cin>>t;
while(t--){
SortedSeqPQMax seq;
vector<int> v;
int n;
cin>>n;
for(int i=0;i<n;i++){
int a;
cin>>a;
v.push_back(a);
}
for(int i=0;i<n;i++){
seq.insert(v.back());
v.pop_back();
}
for(int i=0;i<n;i++){
v.push_back(seq.max());
seq.removeMax();
}
for(int i=0;i<n;i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
}