Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. void print_numbers(char *str)
  2. {
  3. assert(str);
  4. while (auto pos = strpbrk(str, "0123456789")) {
  5. auto len = strspn(pos, "0123456789");
  6. print(pos, pos + len - 1);
  7. str = pos + len;
  8. }
  9. std::cout << std::endl;
  10. }
  11.  
  12. void swap_min_max(double *arr, int n)
  13. {
  14. assert(arr);
  15. auto min = arr, max = arr;
  16. for (auto i = 0; i < n; ++i) {
  17. if (*(arr + i) < *min) min = arr + i;
  18. if (*(arr + i) > *max) max = arr + i;
  19. }
  20. auto temp = *min;
  21. *min = *max;
  22. *max = temp;
  23. }
  24.  
  25. void swap_halves(int *arr, int n)
  26. {
  27. assert(arr);
  28. assert(n % 2 == 0);
  29. for (int i = 0; i < n / 2; ++i) {
  30. std::swap(*(arr + n / 2 + i), *(arr + i));
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement