Skip to content

Commit

Permalink
Permutation Minimization By Deque Issue rjkalash#472
Browse files Browse the repository at this point in the history
Permutation Minimization By Deque Issue Solved
  • Loading branch information
sahil2311sharma authored Oct 3, 2021
1 parent 98f2124 commit 61f8ee5
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions C++ Programs/PermutationMinimizationByDeque.cpp
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;
}

0 comments on commit 61f8ee5

Please sign in to comment.