STL 小白学习(5) stack栈】的更多相关文章

#include <iostream> #include <stack> //stack 不遍历 不支持随机访问 必须pop出去 才能进行访问 using namespace std; void test01() { //初始化 stack<int> s1; stack<int> s2(s1); //stack操作 //首先是压栈 s1.push(); s1.push(); s1.push(); //返回栈顶元素 cout << "栈顶…
目录 头文件 string 目录部分 1.string的定义及初始化 ① 用一个字符串给另一个字符串赋值 ②用字符串常量对字符串进行赋值 ③ 用n个相同的字符对字符串赋值 2.string的运算符及比较符 3.string的一些常用函数 ① size()和length() ② at() ③ find() ⑤ append() stack 目录部分 1.stack的定义 2.常用函数 ① size() ② empty() ③ pop() 与 top() ④ push() queue 目录部分 1.…
#include <iostream> using namespace std; #include <vector> //动态数组 #include <algorithm>//算法 void PrintVector(int v) { cout << v<<" "; } /* STL 容器算法迭代器 基本语法 */ void test01() { vector<int> v; //定义一个容器 指定存放的元素类型 v…
map的构造函数 map<int, string> mapS; 数据的插入:用insert函数插入pair数据,下面举例说明 mapStudent.insert(pair<, "student_one")); mapStudent.insert(pair<, "student_two")); mapStudent.insert(pair<, "student_three")); map迭代器 map<int,…
void test01() { //构造方法 pair<, ); cout << p1.first << p1.second << endl; pair<, "assd"); cout << p2.first << p2.second << endl; pair<int, string> p3 = p2; }…
#include <iostream> using namespace std; #include <set> void printSet(set<int> s) { for (set<int>::iterator it = s.begin(); it != s.end(); it++) { cout << *it << " "; } cout << endl; } //初始化 void test01(…
#include <iostream> using namespace std; #include <list> void printList(list<int>& mlist) { for (list<int>::iterator it = mlist.begin(); it != mlist.end(); it++) { cout << *it << " "; } cout << endl;…
//queue 一端插入 另一端删除 //不能遍历(不提供迭代器) 不支持随机访问 #include <queue> #include <iostream> using namespace std; void test01() { queue<int> q1; q1.push();//尾部插入 q1.push(); q1.push(); q1.pop();//删除队头 cout << q1.back();//返回队尾元素 cout << q1.f…
#include <iostream> #include <deque> //deque容器 双口 using namespace std; void printDeque(deque<int>& d) { for (deque<int>::iterator it = d.begin(); it != d.end(); it++) { cout << (*it) << " "; } cout <<…
#include <iostream> using namespace std; #include <vector> void printVector(vector<int>& v) { for (vector<int>::iterator it = v.begin(); it != v.end(); it++) { cout << (*it) << " "; } cout << endl; }…