fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. void insertion_sort(vector<int> &a){
  6. int n=a.size();
  7. for(int i=1;i<n;i++){
  8. int temp=a[i];
  9. int j = i-1;
  10. while(j>=0 && a[j]>temp){
  11. a[j+1]=a[j];
  12. j--;
  13. }
  14. a[j+1]=temp;
  15. }
  16. }
  17. int main() {
  18. // your code goes here
  19. ios_base::sync_with_stdio(0);
  20. cin.tie(0);
  21. int t;
  22. cin>>t;
  23. while(t--){
  24. int n;
  25. cin>>n;
  26. vector<int> a(n);
  27.  
  28. for(int i=0;i<n;i++)
  29. cin>>a[i];
  30. insertion_sort(a);
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5380KB
stdin
4
8
176 -272 -272 -45 269 -327 -945 176 
2
-274 161
7
274 204 -161 481 -606 -767 -351
2
154 -109
stdout
Standard output is empty