欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

C語(yǔ)言

當(dāng)前位置:主頁(yè) > 軟件編程 > C語(yǔ)言 >

C++ STL入門(mén)教程(6) set(集合)的使用方法

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語(yǔ)言|點(diǎn)擊: 次

一、簡(jiǎn)介

集合(Set)是一種包含已排序?qū)ο蟮年P(guān)聯(lián)容器,不允許有重復(fù)元素。

二、完整程序代碼

/*請(qǐng)務(wù)必運(yùn)行以下程序后對(duì)照閱讀*/ 
 
#include <set> 
#include <iostream> 
using namespace std; 
 
int main() 
{ 
  ///1. 初始化 
  set<int> num; 
  set<int>::iterator iter; 
  cout << num.max_size() << endl;///set容納上限 
  cout << endl; 
 
  ///2. 添加元素 
  for (int i = 0; i < 10; i++) 
    num.insert(i); 
  cout << num.size() << endl; 
  cout << endl; 
 
  ///3. 遍歷 
  ///不同于map,set容器不提供下標(biāo)操作符 
  for (iter = num.begin(); iter != num.end(); iter++) 
    cout << *iter << " " ; 
  cout << endl; 
  cout << endl; 
 
  ///4. 查詢 
  iter = num.find(1); 
  if (iter != num.end()) 
    cout << *iter << endl; 
  else 
    cout << -1 << endl; 
  iter = num.find(99); 
  if (iter != num.end()) 
    cout << *iter << endl; 
  else 
    cout << -1 << endl; 
  cout << endl; 
 
  ///5. 刪除 
  iter = num.find(1); 
  num.erase(iter); 
  cout << num.size() << endl; 
  for (iter = num.begin(); iter != num.end(); iter++) 
    cout << *iter << " " ; 
  cout << endl; 
  cout << endl; 
 
  ///6. 判空與清空 
  if (!num.empty()) 
    num.clear(); 
} 

三、補(bǔ)充

map容器是鍵-值對(duì)的集合,好比以人名為鍵的地址和電話號(hào)碼。相反地,set容器只是單純的鍵的集合。當(dāng)我們想知道某位用戶是否存在時(shí),使用set容器是最合適的。

參考網(wǎng)址:http://www.cplusplus.com/reference/set/set/

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:C++中的函數(shù)匯總

欄    目:C語(yǔ)言

下一篇:C++二分查找算法實(shí)例

本文標(biāo)題:C++ STL入門(mén)教程(6) set(集合)的使用方法

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/1239.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有