Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Sort an array of 0s, 1s and 2s
#include <bits/stdc++.h> using namespace std; void srt(vector<int>&v) { int left=0; int n=(int)v.size(); int right=(int)v.size()-1; for(int i=0;i<=right;i++) { if(v[i]==0) { swap(v[left],v[i]); left++; } else if(v[i]==2) { swap(v[right],v[i]); right--; i--; } } for(int i=0;i<n;i++) { cout<<v[i]<<" "; } cout<<endl; } int main() { //code int t; cin>>t; while(t--) { int n;cin>>n; vector<int>v(n); for(int i=0;i<n;i++) cin>>v[i]; srt(v); } return 0; }
run
|
edit
|
history
|
help
0
მატრიცა#2
Metodos
Simple Interest Calculator
2720
Least missing num
Anagrams
Shultz_Lab2.CPP
NonparaU
map sort
alm7ly