#include <iostream>
#include <deque>
#include <vector>
using namespace std;
const int SIZE = 100;
double sum(const deque<double> &dq)
{
deque<double>::const_iterator p;
double s = 0;
for (p=dq.begin(); p != dq.end(); ++p)
s += *p ;
return s;
}
int main()
{
vector<double> vec(SIZE, 0);
deque<double> deq;
int i;
double sumTotal;
for(i = 0; i < SIZE; i++){
vec[i] = i * 0.6; cout << vec[i] << endl;
}
deq.push_front(vec.front());
deq.push_back(vec.back());
deq.insert(deq.begin()+1, vec.begin()+1, vec.end()-1);
sumTotal = sum(deq);
cout << "sum:" << sumTotal;
}
|