Advertisement
Guest User

vector iterator STL

a guest
May 24th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4. #include <algorithm>
  5. #include <cstdlib>  
  6.  
  7. using namespace std;
  8.  
  9. template<class T> int g(vector<T> *obj){
  10.     vector<T>::iterator p;
  11.     int counter = 0;
  12.     for (p = obj->begin(); p != obj->end(); p++){
  13.         cout << **(p) << " ";
  14.     }
  15.     cout << endl;
  16.     for (p = obj->begin(); p != obj->end(); p++){
  17.         if (p + 1 != obj->end()){
  18.             if (**(p + 1) < 0){
  19.                 **p = 0;
  20.                 counter++;
  21.             }
  22.         }
  23.     }
  24.     cout << endl;
  25.     for (p = obj->end(); p != obj->begin(); p--){
  26.         cout << **(p-1) << " ";
  27.     }
  28.     cout << endl;
  29.     cout << "counter: ";
  30.     return counter;
  31. }
  32.  
  33. int main(){
  34.     vector<double> doubleVector;
  35.     vector<double>::iterator i;
  36.  
  37.     for (int i(1); i < 8; i++){
  38.         double temp = pow(-1, i) * 2 * i ;
  39.         doubleVector.push_back(temp);
  40.     }
  41.    
  42.     vector<double*> pointer;   
  43.     for (i = doubleVector.begin(); i != doubleVector.end(); i++)
  44.     {
  45.         pointer.push_back(&(*i));
  46.     }
  47.  
  48.     cout << endl;
  49.  
  50.     cout << g(&pointer) << endl;
  51.    
  52.     system("pause");
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement