从第三章才开始做题,自己还是有些浮躁,以后看完要把会作的都做完再看下一章。
练习3.1You are given a list, L, and another list P, containing integers sorted in ascending order. The operation printLots(L,P) will print the elements in L that are in positions specified by P. For instance, if P = 1,3,4,6, the elements in positions 1,3,4, and 6 in L are printed. Write the procedure printLots(L, P). You may use only the public STL container operations. What is the running time of your procedure?
下面是源码,写得粗糙,有问题请指出:
//main.cpp
#include <list>
#include <iostream>
using namespace std;
void printLots(const list<int>& printLst, const list<int>& pos) //runtime O(n2)
{
list<int>::const_iterator pit;
for(list<int>::const_iterator it = pos.begin(); it != pos.end(); ++it)
{
pit = pri