min_element 函式的 STL 範例
轉自:http://support.microsoft.com/kb/156619/zh-tw
其他相關資訊
必要的標頭
<algorithm>
原型
template<class InputIterator> inline InputIterator min_element(InputIterator first, InputIterator last)
描述
min_element 演演算法傳回的最小的專案位置中序列 [first, last)。min_element-述詞版本會使用運運算元 < 進行比較。
範例程式碼
////////////////////////////////////////////////////////////////////// // // Compile options needed: /GX // // min_element.cpp : Illustrates how to use the min_element // function. // // Functions: // // min_element - Return the minimum element within a range. // // Written by Kalindi Sanghrajka // of Microsoft Product Support Services, // Software Core Developer Support. // Copyright (c) 1996 Microsoft Corporation. All rights reserved. ////////////////////////////////////////////////////////////////////// // disable warning C4786: symbol greater than 255 character, // okay to ignore #pragma warning(disable: 4786) #include <iostream> #include <algorithm> #include <functional> #include <vector> using namespace std; void main() { const int VECTOR_SIZE = 8 ; // Define a template class vector of int typedef vector<int, allocator<int> > IntVector ; //Define an iterator for template class vector of strings typedef IntVector::iterator IntVectorIt ; IntVector Numbers(VECTOR_SIZE) ; IntVectorIt start, end, it, location ; // Initialize vector Numbers Numbers[0] = 4 ; Numbers[1] = 10 ; Numbers[2] = 10 ; Numbers[3] = 30 ; Numbers[4] = 69 ; Numbers[5] = 70 ; Numbers[6] = 96 ; Numbers[7] = 100 ; start = Numbers.begin() ; // location of first // element of Numbers end = Numbers.end() ; // one past the location // last element of Numbers // print content of Numbers cout << "Numbers { " ; for(it = start; it != end; it++) cout << *it << " " ; cout << " }\n" << endl ; // return the minimum element in the Numbers location = min_element(start, end) ; cout << "The minimum element in Numbers is: " << *location << endl ; }
數字 {4 10 10 30 69 70 96 100}
數字中最小的專案是: 4
相關文章
- STL容器的各個函式方法函式
- 淺析stl仿函式函式
- stl中的sort函式,你真的瞭解嗎函式
- C++(STL原始碼):37---仿函式(函式物件)原始碼剖析C++原始碼函式物件
- quit(code=None)函式和exit(code=None)函式的使用舉例UINone函式
- 遞迴函式例項大全遞迴函式
- 類别範本與函式模板的區別函式
- 例項物件和函式物件的區別物件函式
- 私有建構函式的物件建立例項函式物件
- python例項建立銷燬的函式整理Python函式
- pegasusWMS的jupyter範例
- PHP preg match正規表示式函式的操作例項PHP函式
- 例項解釋NLLLoss損失函式與CrossEntropyLoss損失函式的關係函式ROS
- Python函式每日一講 - frozenset集合函式入門及例項Python函式
- STL區間成員函式及區間演算法總結函式演算法
- 數學建模例題例 2.21 map()函式使用示例函式
- 數學建模例題例 2.22 filter()函式使用示例Filter函式
- 數學建模例題例 2.24 zip()函式使用示例函式
- Python中compile函式的語法及例項!PythonCompile函式
- c++函式模板和類别範本C++函式
- 類别範本物件做函式引數物件函式
- C++ priority_queue為例的比較函式C++函式
- 編碼規範 | Java函式優雅之道(下)Java函式
- 編碼規範 | Java函式優雅之道(上)Java函式
- 邏輯函式的規範正規化:SOP與POS form函式ORM
- Shell中的${}、##和%%使用範例
- 函式計算支援 MySQL 例項繫結函式MySql
- LTSPICE 公式法畫傳遞函式舉例公式函式
- Hive 分析函式lead、lag例項應用Hive函式
- 反射破壞單例的私有建構函式保護反射單例函式
- 數學知識-核函式的通俗解釋例項函式
- main函式的入口函式AI函式
- Golang 註釋規範-類、函式、結構體等Golang函式結構體
- 類别範本中成員函式建立時機函式
- C語言——使用函式輸出指定範圍內的Fibonacci數C語言函式
- Cookie 的特徵與範圍用例Cookie特徵
- JS函式,物件,例項方法,物件方法理解JS函式物件
- Python簡單函式迴圈綜合例項Python函式
- 使用 __get__ 向已有類例項注入函式函式