//有关 STL 标准模板库的函数

/* string 的 */

/*

#include <iostream>

#include <string>

#include <windows.h>

using namespace std;

void stringinit()

{

string s1; //无参构造函数

string s2("helloworld"); //有参构造函数

string s3(10,'h'); //

string s4(s2); //拷贝构造函数

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);

cout << s1 << endl;

cout << s2 << endl;

cout << s3 << endl;

cout << s4 << endl;

}

void stringat() //数据的存储

{

string s1("123456789");

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);

cout << s1[2] << endl; //可能会段错误(越界

cout << s1.at(1) << endl; //可以抛出异常(越界 具体如下

try

{

cout << s1.at(10) << endl;

}

catch (exception &e)

{

cout << e.what() << endl;

}

}

void stringlength()

{

string s1("helloworld");

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |

FOREGROUND_BLUE);

cout << s1.length() << endl;

string s2;

if (s2.empty())

{

cout << "empty string" << endl;

}

}

void stringstr()

{

string s1("helloworld");

const char *ptr = s1.c_str();

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |

FOREGROUND_BLUE);

cout << ptr << endl;

}

void stringcopy()

{

string s1("yohoo");

char buf[32] = {0};

s1.copy(buf,3,2);

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |

FOREGROUND_BLUE);

cout << buf << endl;

}

int main()

{

//stringinit();

//stringat();

//stringlength();

//stringstr();

//stringcopy();

system("pause");

return 0;

}

*/

/* vector */

/*

#include <iostream>

#include <vector>

#include <windows.h>

using namespace std;

void vectorinit()

{

int array[10] = {0,1,2,3,4,5,6,7,8,9};

vector<int> v1;

vector<int> v2(10);

vector<int> v3(array , array + sizeof(array) / sizeof(array[0]));

for (int i = 0; i < (int)v3.size(); i++)

{

cout << v3[i];

}

cout << endl;

vector<int> v4(v3);

for (int i = 0; i < (int)v4.size(); i++)

{

cout << v4[i];

}

cout << endl;

cout << v4.at(2) << endl;

cout << v4[5] << endl;

}

void vectorassgin()

{

int array[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

vector<int> v3(array, array + sizeof(array) / sizeof(array[0]));

vector<int> v1;

v1.assign(array, array + sizeof(array) / sizeof(array[0]));

for (int i = 0; i < (int)v1.size(); i++)

{

cout << v1[i];

}

cout << endl;

v1.assign(5 , 'a');

for (int i = 0; i < (int)v1.size(); i++)

{

cout << v1[i];

}

cout << endl;

v1.swap(v3);

for (int i = 0; i < (int)v1.size(); i++)

{

cout << v1[i];

}

cout << endl;

}

void vectoriterator()

{

vector<int> v1(10,0);

for (int i = 0; i < (int)v1.size(); i++)

{

v1[i] = i + 1;

}

for (vector<int>::iterator it = v1.begin(); it != v1.end(); it++)

{

cout << *it;

}

cout << endl;

}

void vectorinsert()

{

}

int main()

{

//vectorinit();

//vectorassgin();

vectoriterator();

vectorinsert();

system("pause");

return 0;

}

*/

/* deque */

/*

#include <iostream>

#include <deque>

#include <windows.h>

using namespace std;

int main()

{

/*

deque <int> d1;

d1.push_back(1);

d1.push_back(2);

d1.push_back(3);

d1.push_back(4);

d1.push_back(5);

d1.push_front(99);

for (deque<int>::iterator it = d1.begin(); it != d1.end(); it++)

{

cout << *it<<" ";

}

cout << endl;

*/

/*

int array[10] = {3,1,4,7,3,6,4,3,1,3};

deque <int> d1(array,array + sizeof(array) / sizeof(array[0]));

for (deque<int>::iterator it = d1.begin(); it != d1.end();)

{

if (*it == 3)

{

it = d1.erase(it);

}

else

{

it++;

}

}

for (deque<int>::iterator it = d1.begin(); it != d1.end(); it++)

{

cout << *it << " ";

}

cout << endl;

system("pause");

return 0;

}

*/

/* stack */

#include <iostream>

#include <stack>

using namespace std;

int Priority(char ch)

{

switch(ch)

{

case '(':

return 3;

case '*':

case '/':

return 2;

case '+':

case '-':

return 1;

default:

return 0;

}

}

int main()

{

int i = 0, tmp = 0, num1, num2, result;

stack<int> s_opt, s_num;

char opt[64] = {0};

char ch;

cout << "Please input :" << endl;

cin >> opt;

while (opt[i] != '\0' || s_opt.empty() != true)

{

if (opt[i] >= '0' && opt[i] <= '9')

{

tmp = tmp * 10 + opt[i] - '0';

i++;

if (opt[i] > '9' || opt[i] < '0')

{

s_num.push(tmp);

tmp = 0;

}

}

else

{

//操作符进栈

if (s_opt.empty() || (s_opt.top() == '(' && opt[i] != ')')

|| Priority(opt[i]) > Priority(s_opt.top()))

{

s_opt.push(opt[i]);

i++;

continue;

}

if (s_opt.top() == '(' && opt[i] == ')')

{

s_opt.pop();

i++;

continue;

}

if ((opt[i] == ')' && s_opt.top() != '(') ||

Priority(opt[i]) <= Priority(s_opt.top()) || (opt[i] == '\0' && !s_opt.empty()))

{

ch = s_opt.top();

s_opt.pop();

switch(ch)

{

case '+':

num1 = s_num.top();

s_num.pop();

num2 = s_num.top();

s_num.pop();

s_num.push(num1 + num2);

break;

case '-':

num1 = s_num.top();

s_num.pop();

num2 = s_num.top();

s_num.pop();

s_num.push(num2 - num1);

break;

case '*':

num1 = s_num.top();

s_num.pop();

num2 = s_num.top();

s_num.pop();

s_num.push(num1 * num2);

break;

case '/':

num1 = s_num.top();

s_num.pop();

num2 = s_num.top();

s_num.pop();

s_num.push(num2 / num1);

break;

}

}

}

}

result = s_num.top();

cout << result << endl;

return 0;

}

补8-5日复习内容 STL 标准模板库的容器相关推荐

  1. 19.3 C++STL标准模板库大局观-容器的说明和简单应用例续

    19.1 C++STL标准模板库大局观-STL总述.发展史.组成与数据结构谈 19.2 C++STL标准模板库大局观-容器分类与array.vector容器精解 19.3 C++STL标准模板库大局观 ...

  2. C++提高编程----STL标准模板库-常用容器

    STL标准模板库(Standard Template Library)-常用容器 C++的,面向对象和泛型编程,目的就是提高代码的复用性:为了建立数据结构和算法的统一标准,诞生了STL 一.STL初识 ...

  3. 19.1 C++STL标准模板库大局观-STL总述、发展史、组成与数据结构谈

    19.1 C++STL标准模板库大局观-STL总述.发展史.组成与数据结构谈 19.2 C++STL标准模板库大局观-容器分类与array.vector容器精解 19.3 C++STL标准模板库大局观 ...

  4. STL 标准模板库—容器部分【C++】

    STL标准模板库 包含内容: 容器类:vector.list.deque.set.map等 迭代器:"泛型指针",每个容器都有自己的迭代器,[vector和deque的迭代器是随机 ...

  5. 信息学奥赛中的STL(标准模板库)--2022.09.30

    1.信息学奥赛一本通 第5版 第8章 C++实用技巧与模版库(6节) 第一节  排序算法 第二节 运算符重载 第三节  字符串(string) 第四节 FIFO队列和优先队列 第五节  动态数组 第六 ...

  6. C++ STL 标准模板库介绍与入门

    目录 1.概述 1.1.C++ 标准库 1.2.Boost库 2.STL 版本 2.1.HP 原始版本 2.2.P. J. 实现版本 2.3.RW 实现版本 2.4.SGI 实现版本 2.5.STLp ...

  7. 【跟学C++】C++STL标准模板库——算法详细整理(下)(Study18)

    文章目录 1.简介 2.STL算法分类及常用函数 2.2.变序算法(二) 2.2.1 替换算法(2个) 2.2.2 排序算法(6个) 2.2.3 分区算法(4个) 2.2.4 可用于排序容器的算法(3 ...

  8. C++入门到精通 ——第七章 STL标准模板库大局观

    七.STL标准模板库大局观 Author: XFFer_ 先分享一本 <C++ 标准库 第二版> ,望在STL的道路上从入门到放弃!(开玩笑的啦,愈行愈远~) 链接: https://pa ...

  9. STL(标准模板库)理论基础与容器

    10.1 STL(标准模板库)理论基础 10.1.1基本概念 STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称.现然主要出现在C++中,但在被 ...

最新文章

  1. C++中sizeof问题
  2. [armv9]-ARMV8/ARMV9安全架构介绍(ARMv9 CCA)
  3. 声学漫谈之三:听觉的分辨力
  4. .net 面试题系列文章一(附答案)
  5. Android之旅---广播(BroadCast)
  6. 前端工程构建工具——Yeoman
  7. Namomo Fish(Easy) Round 1
  8. Android 检查版本更新 Server后台下载
  9. 复习--linux目录及文件操作
  10. Python 的一个脚本错误可能会废掉 150 多个项目!
  11. monkey命令的使用
  12. 【DBA | IT人生】数据库解惑系列
  13. 什么是VBA编程语言?
  14. 物流(Logistics)的概念
  15. INSERT INTO… ON DUPLICATE KEY UPDATE用法
  16. 超详细的k8s对接ceph RBD存储
  17. class.forName
  18. FutureTask源码解析二
  19. spring cloud 之 Ribbon
  20. Java实现小型酒店管理系统。

热门文章

  1. php实现队列上传,php实现队列
  2. Ubuntu Qt编译报错 stdlib.h: No such file or directory
  3. java 设置光标_java光标位置怎么设置 java设置光标位置方法
  4. 解决vc2008 utf8中文字符串报错 C2001常量中有换行符
  5. java -jar 停止_推荐:Linux启动Java程序jar包Shell脚本
  6. linux源代码调用,linux – 哪里可以找到系统调用源代码?
  7. mysql bingip,MySQL报错Ignoring query to other database的真正原因
  8. mysql嵌入式语句_MySQL/MariaDB 语句速查笔记
  9. linux中负载值为多少正常_Linux load average负载量分析与解决思路
  10. pstack 安装linux_详解命令-pstack