将向量< T> :: iterator与向量< T> :: reverse

编程入门 行业动态 更新时间:2024-10-23 13:38:08
本文介绍了将向量< T> :: iterator与向量< T> :: reverse_iterator进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在做一个练习,我有一个向量,我正在写一个反向算法,通过使用一个反向和一个正向(正向)迭代器来反转向量的内容。但是,我无法比较迭代器。

I am working on an exercise where I have a vector and I am writing my own reverse algorithm by using a reverse and a normal (forward) iterator to reverse the content of the vector. However, I am not able to compare the iterators.

int vals[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; vector<int> numbers(vals, vals + 10); vector<int>::iterator start = numbers.begin(); vector<int>::reverse_iterator end = numbers.rend();

我有一个先前的算法通过使用两个迭代器逆向向量,能够使用!=运算符在它们之间进行比较。我的猜测是获得底层的指针或索引在向量中彼此,但如何获得指针/索引?

I have a previous algorithm for reversing the vector by using two iterators, however in this task I am not able to compare them using the != operator between them. My guess would be to get the underlying pointers or indexes in the vector with each other but how do I get the pointers/index?

推荐答案

使用 base()返回的迭代器进行比较$ c> : it == rit.base() - 1 。

Do a comparison using the the iterator returned by base(): it == rit.base() - 1.

更多推荐

将向量&lt; T&gt; :: iterator与向量&lt; T&gt; :: reverse

本文发布于:2023-11-12 04:26:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580507.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向量   amp   lt   reverse   iterator

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!