-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting1.cpp
More file actions
39 lines (36 loc) · 795 Bytes
/
sorting1.cpp
File metadata and controls
39 lines (36 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @file sorting1.cpp
* @author long (you@domain.com)
* @brief sorting 1
* @version 0.1
* @date 2023-03-18
*
* @copyright Copyright (c) 2023
*
*/
#include <iostream>
#include <algorithm>
int main() {
int t;
std::cin >> t;
while (t--) {
int n, arr[1001];
std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> arr[i];
}
std::sort(arr, arr + n);
// for(int i=0; i < n; i++) {
// std::cout << arr[i] << " ";
// }
int head{0}, tail{n-1};
while(head < n/2) {
std::cout << arr[tail--] << " ";
std::cout << arr[head++] << " ";
}
if(n%2!=0) {
std::cout << arr[head];
}
std::cout << std::endl;
}
}