📄 lists.strlist.search.html
字号:
<html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><head><!-- #BeginEditable "doctitle" --> <title>PTypes: lists: strlist: search</title><!-- #EndEditable --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link rel="stylesheet" href="styles.css"></head><body bgcolor="#FFFFFF" leftmargin="40" marginwidth="40"><p><a href="../index.html"><img src="title-1.7.gif" width="213" height="34" alt="C++ Portable Types Library (PTypes) Version 1.7" border="0"></a> <hr noshade><!-- #BeginEditable "body" --> <p class="hpath"><a href="index.html">Top</a>: <a href="basic.html">Basic types</a>: <a href="lists.html">Lists</a>: <a href="lists.strlist.html">strlist</a>: Search </p><blockquote> <pre class="lang">#include <ptypes.h>bool search(const strlist& s, const string& key, int& index);int find(const strlist& s, const string& key);int indexof(const strlist& s, unknown* obj);virtual int strlist::compare(const string& key1, const string& key2);</pre></blockquote><p><span class="def">bool search(const strlist& s, const string& key, int& index)</span> works only on sorted lists and returns <span class="lang">true</span> if the given string <span class="lang">key</span> was found in the list <span class="lang">s</span>, or <span class="lang">false</span> otherwise. The parameter <span class="lang">index</span> returns either the index (position) of the item found, or the position where this item should be placed if it does not exist in the list.</p><p><span class="def">int find(const strlist& s, const string& key)</span> finds the given string <span class="lang">key</span> in the list <span class="lang">s</span>. It returns the index of the item, or <span class="lang">-1</span> if the item was not found. This function works both on sorted and unsorted lists, however, a sorted list provides better performance.</p><p><span class="def">int indexof(const strlist& s, unknown* obj)</span> finds the given object <span class="lang">obj</span> in the list <span class="lang">s</span>. It returns the index of the item, or <span class="lang">-1</span> if the item was not found. This function works both on sorted and unsorted lists, but unlike <span class="lang">find()</span>, it always uses linear search method.</p><p><span class="def">virtual int strlist::compare(const string& key1, const string& key2)</span> is a protected virtual method that can be overridden to provide alternate comparison algorithm for sorted lists. The overridden function should return -1, 0 or 1 as a result of comparing keys <span class="lang">key1</span> and <span class="lang">key2</span>.</p><p class="seealso">See also: <a href="lists.strlist.constructors.html">Constructors/destructors</a>, <a href="lists.strlist.manipulation.html">Manipulation</a></p><!-- #EndEditable --> <hr size="1"><a href="../index.html" class="ns">PTypes home</a></body><!-- #EndTemplate --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -