Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void rearrange_max_min(int *nums, int n){
- int *temp = new int[n];
- int min_num = 0, max_num = n - 1;
- bool f = true;
- for(int i = 0; i < n; ++i){
- if(f) temp[i] = nums[max_num--];
- else temp [i] = nums [min_num++];
- f = !f;
- }
- for(int i = 0; i < n; ++i) nums[i] = temp[i];
- }
- int main() {
- int nums[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- int n = sizeof(nums) / sizeof(nums[0]);
- rearrange_max_min(nums, n);
- for(int i = 0; i < n; ++i) cout << nums[i] << " ";
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement