Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. void rearrange_max_min(int *nums, int n){
  4. int *temp = new int[n];
  5. int min_num = 0, max_num = n - 1;
  6. bool f = true;
  7. for(int i = 0; i < n; ++i){
  8. if(f) temp[i] = nums[max_num--];
  9. else temp [i] = nums [min_num++];
  10. f = !f;
  11. }
  12. for(int i = 0; i < n; ++i) nums[i] = temp[i];
  13.  
  14.  
  15. }
  16. int main() {
  17. int nums[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  18. int n = sizeof(nums) / sizeof(nums[0]);
  19. rearrange_max_min(nums, n);
  20. for(int i = 0; i < n; ++i) cout << nums[i] << " ";
  21. cout << endl;
  22. return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement