SStive39

OOP_k2l1v12

Sep 26th, 2021
1,043
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <typename T>
  6. void remover(T*& _arr, int size, bool (*func)(T)) {
  7.     T* new_arr = new T[size];
  8.     int new_pos = 0;
  9.     for (int i = 0; i < size; i++)
  10.         if (!func(_arr[i])) {
  11.             new_arr[new_pos] = _arr[i];
  12.             new_pos++;
  13.         }
  14.     _arr = new_arr;
  15. };
  16.  
  17. bool is_odd(int n) {
  18.     return n % 2;
  19. }
  20.  
  21. int main() {
  22.     int* A = new int[10];
  23.     for (int i = 0; i < 10; i++)
  24.         A[i] = i+1;
  25.    
  26.     remover(A, 10, is_odd);
  27.    
  28.     for (int i = 0; i < 10; i++)
  29.         cout << A[i] << " ";
  30.    
  31.     return 0;
  32. }
RAW Paste Data