日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

c ++ stl_获取列表的第一个和最后一个元素| C ++ STL

發布時間:2025/3/11 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c ++ stl_获取列表的第一个和最后一个元素| C ++ STL 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

c ++ stl

Given a list with some of the elements, we have to access its first and last elements of the list in C++ (STL) program.

給定包含某些元素的列表,我們必須在C ++(STL)程序中訪問列表的第一個和最后一個元素。

列表的front()和back()函數 (front() and back() function of the list)

These are two functions which can be used to get the first and last element of the list. 'front()' returns the first element and 'back()' returns the last element.

這是兩個函數,可用于獲取列表的第一個和最后一個元素。 'front()'返回第一個元素, 'back()'返回最后一個元素。

Let's implement the program below...

讓我們實現下面的程序...

Example:

例:

Input:List: [10, 20, 30, 40, 50]Output:First element: 10Last element: 50

Program:

程序:

#include <iostream> #include <list> using namespace std;int main() {list<int> iList = {10, 20, 30, 40, 50};cout<<"First element: "<<iList.front()<<endl;cout<<"Last element: "<<iList.back()<<endl;return 0; }

Output

輸出量

First element: 10 Last element: 50

翻譯自: https://www.includehelp.com/stl/get-the-first-and-last-element-of-the-list.aspx

c ++ stl

總結

以上是生活随笔為你收集整理的c ++ stl_获取列表的第一个和最后一个元素| C ++ STL的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。