stl向量最大值_C ++ STL中向量的最小和最大元素

stl向量最大值

Given a vector and we have to find the smallest (minimum) and largest (maximum) elements.

給定一個向量,我們必須找到最小(最小)和最大(最大)元素。

查找向量的最小和最大元素 (Finding vector's minimum & maximum elements)

To find minimum element of a vector, we use *min_element() function and to find the maximum element, we use *max_element() function.

要找到向量的最小元素,請使用* min_element()函數 ,要找到最大元素,請使用* max_element()函數

Syntax:

句法:

    *max_element(iterator start, iterator end);
*min_element(iterator start, iterator end);

Here, iterator start, iterator end are the iterator positions in the vector between them we have to find the minimum and maximum value.

在這里, 迭代器開始,迭代器結束是它們之間向量中迭代器的位置,我們必須找到最小值和最大值。

These functions are defined in <algorithm> header or we can use <bits/stdc++.h> header file.

這些函數在<algorithm>頭文件中定義,或者我們可以使用<bits / stdc ++。h>頭文件。

Example:

例:

    Input:
vector<int> v1{ 10, 20, 30, 40, 50, 25, 15 };
cout << *min_element(v1.begin(), v1.end()) << endl;
cout << *max_element(v1.begin(), v1.end()) << endl;
Output:
10
50

C ++ STL程序查找向量的最小和最大元素 (C++ STL program to find minimum and maximum elements of a vector )

//C++ STL program to append a vector to a vector
#include <bits/stdc++.h>
using namespace std;
int main()
{
//vector declaration
vector<int> v1{ 10, 20, 30, 40, 50, 25, 15 };
int min = 0;
int max = 0;
//finding minimum  & maximum element
min = *min_element(v1.begin(), v1.end());
max = *max_element(v1.begin(), v1.end());
cout << "minimum element of the vector: " << min << endl;
cout << "maximum element of the vector: " << max << endl;
return 0;
}

Output

輸出量

minimum element of the vector: 10
maximum element of the vector: 50

翻譯自: https://www.includehelp.com/stl/minimum-and-maximum-elements-of-a-vector.aspx

stl向量最大值

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541766.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541766.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541766.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

oracle如何設置備份計劃任務,Oracle數據庫設置任務計劃備份一周的備份記錄

Oracle 數據庫備份&#xff1a;--保留最近一周的備份記錄&#xff1b;正文&#xff1a;開始代碼如下:echo 設置備份文件存放文件夾...set "tbufE:\Cway\backup"echo 設置備份文件名(以星期幾命名&#xff0c;即備份文件只保存最近一周)...set name%date%set name%nam…

索引(轉載自百度百科)

Oracle索引 編輯本詞條缺少信息欄、名片圖&#xff0c;補充相關內容使詞條更完整&#xff0c;還能快速升級&#xff0c;趕緊來編輯吧&#xff01;在oracle索引是一種供服務器在表中快速查找一個行的數據庫結構。合理使用索引能夠大大提高數據庫的運行效率。目錄 1 概念及作用 2…

阿姆斯特朗數_阿姆斯特朗的功能依賴公理 數據庫管理系統

阿姆斯特朗數Armstrong axioms are a complete set of inference rules or axioms, introduced and developed by William W. Armstrong in 1974. The inference rules are sound which is used to test logical inferences of functional dependencies. The axiom which also …

ORACLE JOB 失敗 查看,Oracle JOB異常中斷原因分析

注釋今天研發同事找我確認 PKG_WMS.proc_TaskMain 存儲的 job 是否還在運行&#xff0c;竟發現 dba_jobs.NEXT_DATE4000/1/1&#xff0c;如下看看究竟原因吧~JOB 信息&#xff1a;參數&#xff1a;BROKEN : 中斷標記 ,N 啟動、Y 中斷 --> DBMS_JOBS.BROKEN(job_id,TRUE/FA…

ruby打印_Ruby程序打印一個數字的乘法表

ruby打印打印乘法表 (Printing multiplication table) This requires a very simple logic where we only have to multiply the number with digits from 1 to 10. This can be implemented by putting the multiplication statement inside a loop. We have mentioned two wa…

步驟1:JMeter 錄制腳本接口測試

JMeter 常用測試方法簡介 1.下載安裝 http://jmeter.apache.org/download_jmeter.cgi 安裝JDK&#xff0c;配置環境變量JAVA_HOME. 系統要求&#xff1a;JMeter2.11 需要JDK1.6以上的版本支持運行 2.學習Jmeter元件 http://jmeter.apache.org/usermanual/component_reference.h…

模擬斷電oracle數據不一致,Oracle數據庫案例整理-Oracle系統運行時故障-斷電導致數據文件狀態變為RECOVER...

1.1 現象描述異常斷電&#xff0c;數據庫數據文件的狀態由ONLINE變為RECOVER。系統顯示如下信息&#xff1a;SQL> select file_name ,tablespace_name ,online_status from dba_data_files;FILE_NAME---------------------------------------------------------------…

python日歷模塊_Python日歷模塊| prmonth()方法與示例

python日歷模塊Python calendar.prmonth()方法 (Python calendar.prmonth() Method) prmonth() method is an inbuilt method of the calendar module in Python. It works on simple text calendars and prints the calendar of the given month of the given year. Also, the…

多例模式

多例&#xff1a;只是單例的一種延伸 不必過于在意各種模式的名字&#xff0c;重要的是學會融會貫通&#xff0c;把生產的car放到集合中 類似JDBC 的連接池 把連接對象放到池中 多例模式特點&#xff1a; 1. 多例類可以有多個實例 2. 多例類必須自己創建自己的實例&a…

Oracle public view,【易錯概念】以太坊Solidity函數的external/internal,public/private,view/pure/payable區別...

1. 函數類型&#xff1a;內部(internal)函數和外部(external)函數函數類型是一種表示函數的類型。可以將一個函數賦值給另一個函數類型的變量&#xff0c;也可以將一個函數作為參數進行傳遞&#xff0c;還能在函數調用中返回函數類型變量。 函數類型有兩類&#xff1a;- 內部(i…

c-style字符字符串_C字符串-能力問題與解答

c-style字符字符串C programming String Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Strings, String is the set of characters and String related Aptitude Questions and Answers you will find here. C編程Stri…

PHP Smarty template for website

/******************************************************************************* PHP Smarty template for website* 說明&#xff1a;* 之前一直在想將MVC的方式加在PHP做的網站上&#xff0c;這樣比較好處理&#xff0c;相對來說比較好* 處理…

ftp連接oracle服務器,使用SSL加密連接FTP - 架建SSL安全加密的FTP服務器(圖)_服務器應用_Linux公社-Linux系統門戶網站...

四、使用SSL加密連接FTP啟用Serv-U服務器的SSL功能后&#xff0c;就可以利用此功能安全傳輸數據了&#xff0c;但FTP客戶端程序必須支持SSL功能才行。 如果我們直接使用IE瀏覽器進行登錄則會出現圖4顯示的錯誤信息&#xff0c;一方面是以為沒有修改默認的端口21為990&#xff0…

c# 情感傾向_C否則-能力傾向問題與解答

c# 情感傾向C programming if else Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on condition statements – if else, nested if else, ladder if else, conditional operators etc. C語言編程如果有問題&#xff0c;請…

springboot中使用緩存shiro-ehcache

在pom.xml中注入緩存依賴&#xff0c;版本(Sep 09, 2016)spring-context-support 包含支持UI模版&#xff08;Velocity&#xff0c;FreeMarker&#xff0c;JasperReports&#xff09;&#xff0c; 郵件服務&#xff0c; 腳本服務(JRuby)&#xff0c; 緩存Cache&#xff08;EHCa…

oracle 微信公眾號,關于微信公眾號貼代碼的方法

微信公眾號碼上貼代碼一直一來都是個頭疼的問題。吐槽一句&#xff1a;要是后臺編輯器支持markdown就好了。今天教大家用在線markdown排版工具&#xff0c;把代碼完美貼到微信公眾號上。長話短說&#xff0c;今天用到的兩個工具&#xff1a;首先&#xff0c;以一段代碼為例。假…

計算理論 形式語言與自動機_下推式自動機(PDA)| 計算理論

計算理論 形式語言與自動機Pushdown Automaton (PDA) is a kind of Automaton which comes under the theory of Computation that appoints stack. The word Pushdown stands due to the fact that the stack can be pushed down as operations can only work on the elements…

運維人員究竟如何提升價值,持續獲得高薪?

作者簡介&#xff1a;老男孩&#xff0c;北京老男孩IT教育創始人&#xff0c;17年IT經驗&#xff0c;資深Linux實戰專家&#xff0c;IT培訓界實戰派頂尖大師&#xff0c;國內將實戰心理學體系大量注入IT運維培訓領域的第一人&#xff0c;多本IT暢銷圖書作者&#xff0c;51CTO金…

Webservice soap wsdl區別之個人見解

Web Service實現業務訴求&#xff1a;Web Service是真正“辦事”的那個&#xff0c;提供一種辦事接口的統稱。WSDL提供“能辦的事的文檔說明”&#xff1a;對要提供的服務的一種描述格式。我想幫你的忙&#xff0c;但是我要告訴你我都能干什么&#xff0c;以及干這些事情需要的…

java uuid靜態方法_Java UUID nameUUIDFromBytes()方法及示例

java uuid靜態方法UUID類名UUIDFromBytes()方法 (UUID Class nameUUIDFromBytes() method) nameUUIDFromBytes() method is available in java.util package. java.util包中提供了nameUUIDFromBytes()方法 。 nameUUIDFromBytes() method is used to get a UUID constructed fr…