Advertisement
sellmmaahh

popravni-2014-zad6-Kumulativna Suma

Jul 31st, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdexcept>
  4. #include <list>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. template < typename TipPok1, typename TipPok2>
  10. TipPok2 KumulativnaSuma (TipPok1 It1, TipPok1 It2, TipPok2 It3) {
  11.     int brojac{1};
  12.  
  13.     for (auto p(It1); p!=It2; p++, brojac++) {
  14.         auto q(It1);
  15.         for (int i=0; i<brojac; i++)
  16.             *It3+=*q++;
  17.  
  18.  
  19.     It3++;
  20.     }
  21.     return It3;
  22. }
  23. int main () {
  24.     list<int> l{1,2,3,4,5,6,7,8};
  25.     vector<int> vek(l.size());
  26.     KumulativnaSuma(l.begin(), l.end(), vek.begin());
  27.     for (auto x: vek) cout<<x<<" ";
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement