-
Notifications
You must be signed in to change notification settings - Fork 643
/
3.6.cpp
46 lines (42 loc) · 834 Bytes
/
3.6.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
#include <iostream>
#include <cstdlib>
#include <stack>
#include <queue>
using namespace std;
void Qsort(stack<int> &s){
priority_queue< int,vector<int>,greater<int> > q;
while(!s.empty()){
q.push(s.top());
s.pop();
}
while(!q.empty()){
s.push(q.top());
q.pop();
}
}
stack<int> Ssort(stack<int> s){
stack<int> t;
while(!s.empty()){
int data = s.top();
s.pop();
while(!t.empty() && t.top()>data){
s.push(t.top());
t.pop();
}
t.push(data);
}
return t;
}
int main(){
srand((unsigned)time(0));
stack<int> s;
for(int i=0; i<10; ++i)
s.push((rand()%100));
s = Ssort(s);
//Qsort(s);
while(!s.empty()){
cout<<s.top()<<" ";
s.pop();
}
return 0;
}