日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

c++ set有序性

發布時間:2025/6/15 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c++ set有序性 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? ? ? ?set在執行插入操作的時候會自動排序,下面看一段代碼。

#include <iostream> #include <set> #include <string.h>using namespace std;int main() {std::pair<int,string> Entry1 = {1,"111"};std::pair<int,string> Entry2 = {2,"222"};std::pair<int,string> Entry3 = {3,"333"};std::pair<int,string> Entry4 = {4,"444"};set<std::pair<int,string>> list;list.insert(Entry3);list.insert(Entry4);list.insert(Entry2);list.insert(Entry1);std::set<std::pair<int,string>>::const_iterator it = list.begin();for(; it!=list.end();++it){cout << it->first;}return 0; }

? ? ? ? ?打印:1234

? 我插入的時候是亂序,現在輸出是有序的了。注意對于std::pair,它是first成員進行排序的。

總結

以上是生活随笔為你收集整理的c++ set有序性的全部內容,希望文章能夠幫你解決所遇到的問題。

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