
C++ STL容器
Pink&Sakura
C、C++、Java、前端
展开
-
STL中栈stack 的使用方法
empty() 堆栈为空则返回真 pop() 移除栈顶元素 (删除) push() 在栈顶增加元素 (增加) size() 返回栈中元素数目 top() 返回栈顶元素,不删除(获取) #include <iostream> #include <stack> using namespace std; int main() { stack<int> s; //直接入栈 s.push(1); s.push(2); s.push(3); //手动原创 2021-11-28 00:18:30 · 804 阅读 · 0 评论 -
C++的STL容器中sort()函数的使用方法
#include<iostream> #include<algorithm>//sort()函数所需头文件 using namespace std; int main() { int a[10] = { 4,5,9,3,8,2,1,4,0,3 };//初始化数组 for (int i = 0; i < 10; i++) cout << a[i]; cout << endl; sort(a, a + 10);//没有第三个.原创 2021-11-27 22:49:42 · 903 阅读 · 0 评论