fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. void selectionSort(vector<int> &a,int n){
  4. for(int i = 0; i < n-1; i++){
  5. int idx= i;
  6. for(int j = i + 1;j < n; j++){
  7. if( a[j] < a[idx]){
  8. idx = j;
  9. }
  10. }
  11. swap(a[i],a[idx]);
  12. }
  13. }
  14. void solve() {
  15. int n;
  16. cin >> n;
  17. vector<int> a(n);
  18. for (int i = 0; i < n; i++) cin >> a[i];
  19. selectionSort(a,n);
  20. int left = 0, right = n - 1;
  21. vector<int> res;
  22. while (left <= right) {
  23. res.push_back(a[right--]);
  24. if (left <= right) {
  25. res.push_back(a[left++]);
  26. }
  27. }
  28. for (int num : res) {
  29. cout << num << " ";
  30. }
  31. cout << endl;
  32. }
  33. int main() {
  34. int t;
  35. cin >> t;
  36. while (t--) {
  37. solve();
  38. }
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.06s 5292KB
stdin
Standard input is empty
stdout