自己做的数据结构与算法分析(英文3版,weiss写的)的一些课后题

本文探讨如何使用STL中的迭代器来实现一个名为printLots的函数,该函数接受两个按升序排序的整数列表,L和P,分别表示列表和打印位置。函数的目标是在L中打印由P指定位置的元素。提供了两种实现方式,分别是O(n^2)和疑似O(n)的时间复杂度,并附带了一个示例程序进行验证。
摘要由CSDN通过智能技术生成

从第三章才开始做题,自己还是有些浮躁,以后看完要把会作的都做完再看下一章。

练习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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值