习题 3.1

该博客讨论了如何使用STL容器操作来实现一个名为Print的函数,该函数根据给定的索引列表P从列表L中打印元素。问题要求在升序排序的整数列表L和P中,按P中指定的位置打印L的元素。提供的代码示例展示了这种实现,并询问了该过程的时间复杂度。
摘要由CSDN通过智能技术生成

Question:

3.1 you are given a list, L, and another list P,containing integers sorted in ascending order, The operation Print(L,P) will print the elements in L that are in positions specified

by P. For instance, if P = 1,3,4,6, the element in positions 1,3,4 and 6 in L are printed. You may use only the public STL container operations.

  What's the running time of your procedure?


Code is as following:

#include <list>
#include <iostream>
#include <ctime>
#include <algorithm>
#include <iomanip>
typedef std::list<int> lisInt;
void Print(lisInt L, lisInt P);
const int LIMIT{ 100 };
int main()
{
	/*Creat a random list*/
	lisInt List1;
	srand(time(0));
	int i = 0;
	while (i++ < LIMIT)
		List1.push_back(rand() % 100);
	List1.sort();
	std::cout << "\nList1 after soring:\n";
	for (auto x : List1)
		std::cout << std::
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值