Pascal's triangle: Difference between revisions

→‎{{header|C++}}: replaced new/delete with std::vector
(→‎{{header|C++}}: replaced new/delete with std::vector)
Line 134:
<cpp>#include <iostream>
#include <algorithm>
#include <vector>
 
void genPyrN(int rows) {
if (rows < 0) return;
// save the last row here
std::vector<int> *last(1, = new int[1]);
last[0] = 1;
std::cout << last[0] << std::endl;
for (int i = 1; i <= rows; i++) {
// work on the next row
std::vector<int> *thisRow = new int[i+1];
thisRow[0] = last[0].reserve(i+1); // beginning of row
std::transformthisRow.push_back(&last[0], &last[i], &last[1], &thisRow[1], std::plus<int>.front()); // middlebeginning of row
std::transform(last.begin(), last.end()-1, last.begin()+1, std::back_inserter(thisRow), std::plus<int>()); // middle of row
thisRow[i] = .push_back(last[i-1].back()); // end of row
 
delete [] last.swap(thisRow);
last = thisRow;
 
for (int j = 0; j <= i; j++)
Line 156:
std::cout << std::endl;
}
 
delete [] last;
}</cpp>
 
973

edits