forked from rjkalash/hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permutation Minimization By Deque Issue rjkalash#472
Permutation Minimization By Deque Issue Solved
- Loading branch information
1 parent
98f2124
commit 61f8ee5
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*---------------------------------------Header Files---------------------------------------*/ | ||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
/*---------------------------------------MACROS---------------------------------------*/ | ||
|
||
#define times_run long long ___tc=1; cin >> ___tc; while (___tc-- ) | ||
#define rep(i,x,y) for(int i=x;i<y;i++) | ||
|
||
#define pb push_back | ||
#define pf push_front | ||
|
||
#define nl cout<<"\n"; | ||
|
||
/*---------------------------------------Input/Output---------------------------------------*/ | ||
|
||
void start_func() | ||
{ | ||
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); | ||
|
||
#ifndef ONLINE_JUDGE | ||
freopen("input.txt", "r", stdin); | ||
freopen("output.txt", "w", stdout); | ||
#endif | ||
} | ||
|
||
/*---------------------------------------Main Code---------------------------------------*/ | ||
|
||
void chalochale() | ||
{ | ||
int n,node; | ||
cin>>n>>node; | ||
|
||
deque<int> dq; | ||
dq.push_back(node); | ||
rep(i, 1, n) | ||
{ | ||
cin >> node; | ||
if (node > dq[0]) | ||
{ | ||
dq.pb(node); | ||
} | ||
else | ||
{ | ||
dq.pf(node); | ||
} | ||
} | ||
while (!dq.empty()) | ||
{ | ||
cout << dq.front() << " "; | ||
dq.pop_front(); | ||
} | ||
} | ||
|
||
int32_t main() | ||
{ | ||
start_func(); | ||
times_run | ||
{ | ||
chalochale(); | ||
nl | ||
} | ||
return 0; | ||
} |