简体   繁体   English

标准库中有子序列算法吗?

[英]Is there a subsequence algorithm in the Standard Library?

I'm looking for a Standard Library function that returns true if the range [first2, last2) is present within the range [first1, last1) .我正在寻找一个标准库 function 如果范围[first2, last2)存在于[first1, last1)范围内,则返回 true 。 Something with a name like std::is_subsequence .名称类似于std::is_subsequence的东西。 It seems that something like this would be obvious to be in the Standard but for some reason it's not there (or I just can't find it at the least).似乎这样的东西在标准中很明显,但由于某种原因它不存在(或者我至少找不到它)。 Is there a function or method out there that does this?是否有 function 或方法可以做到这一点?

std::search in <algorithm> std::search<algorithm> std::search

std::search at cplusplus.com std :: search在cplusplus.com
std:: search at cppreference.com std ::在cppreference.com上搜索

Search range for subsequence 子序列的搜索范围
Searches the range [first1,last1) for the first occurrence of the sequence defined by [first2,last2), and returns an iterator to its first element, or last1 if no occurrences are found. 在范围[first1,last1)中搜索由[first2,last2)定义的序列的第一个匹配项,然后将迭代器返回到其第一个元素;如果找不到匹配项,则返回last1。

It depends on whether your sequenses are ordered and how you are going to determine that one sequence is present inside another sequence. 这取决于您的序列是否有序,以及如何确定一个序列是否存在于另一序列中。 For example for ordered sequences there is algorithm std::include . 例如,对于有序序列,有算法std::include For unordered sequences you can check that one sequence is an interval of an other sequence. 对于无序序列,您可以检查一个序列是否是另一序列的间隔。 These are algorithms std::search and std::find_end . 这些是std::searchstd::find_end

I think there are some differences here.我认为这里有一些不同之处。 Substring and subsequence are different. Substringsubsequence不同。 The former requires continuity and the latter does not.前者需要连续性,后者不需要。 std::search() can only check substrings, not subsequences std::search() 只能检查子字符串,不能检查子序列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM