当前位置:网站首页>Leetcode problem solving 2.1.1

Leetcode problem solving 2.1.1

2022-07-06 09:04:00 Long time no see 0327

distance() The function is used to calculate the number of elements in the range represented by two iterators

template<class Inputlterator>
    typename iterator_traits<Inputlterator>::difference_type distance(Inputlterator first, Inputlterator last);
#include<iostream>
#include<iterator>	
#include<list>

using namespace std;

int main() {
	//  Create an empty list Containers 
	list<int> mylist;
	//  Empty list Add elements to the container 0~9
	for (int i = 0; i < 10; i++) {
		mylist.push_back(i);
	}
	//  Appoint 2 Two way iterators , Used to execute a certain interval 
	list<int>::iterator first = mylist.begin();		//  Point to elements 0
	list<int>::iterator last = mylist.end();		//  Point to elements 9 The position after 
	//  obtain [first, last) Number of elements in the range 
	cout << "distance() = " << distance(first, last);
	return 0;
}

unique The function of the function is to remove duplicate elements . namely “ Delete ” All adjacent repeating elements in the sequence ( Keep only one )

原网站

版权声明
本文为[Long time no see 0327]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060849180210.html