
STL
谛听-
线上幽灵
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
STL---迭代器
#include "iostream"#include "vector"using namespace std;int main(){ vector<int> v; vector<int>::iterator it; // !! 定义 int i, sum; for(i=0; i<10; i++) v.push_back(i);原创 2016-03-04 16:13:58 · 283 阅读 · 0 评论 -
函数作为参数
#include "iostream"using namespace std;int f1(int n){ return n;}int f2(int n){ return n + n;}void F(int (*pf)(int), int n){ cout << pf(n) << endl;}int main(){ F(f1, 5); F(f2原创 2017-01-31 19:59:54 · 271 阅读 · 0 评论 -
异常
#include "iostream"#include "string"using namespace std;void f(string s) throw(string){ cout << s << endl; if(s == "error") throw string("exception");}void show1(){ try {原创 2017-01-31 21:01:16 · 291 阅读 · 0 评论 -
STL---排序
#include "iostream"#include "vector"#include "algorithm"using namespace std;struct C{ int v; // 从小到大排 bool operator < (const struct C &c) const { return v < c.v; }};struc原创 2016-10-03 23:34:37 · 340 阅读 · 0 评论 -
结构体可直接赋值
#include "iostream"#include "vector"#include "algorithm"using namespace std;struct C{ int a; vector<int> v; // 从小到大排 bool operator < (const struct C &c) const { return v <原创 2017-03-09 14:26:57 · 1953 阅读 · 0 评论 -
leetcode---Queue Reconstruction by Height
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this p原创 2017-04-28 22:24:09 · 341 阅读 · 0 评论 -
leetcode---Power of Two---lower_bound,upper_bound,binary_search
Given an integer, write a function to determine if it is a power of two.Credits: Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.Subscribe to see which compa原创 2016-04-07 17:14:40 · 487 阅读 · 0 评论 -
Two Sum II - Input array is sorted---lower_bound
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers suc原创 2017-07-08 19:35:09 · 260 阅读 · 0 评论 -
模拟实现智能指针 scope_ptr、shared_ptr
转自 http://blog.51cto.com/10740184/1753183scope_ptr注意,将拷贝构造函数和拷贝复制运算符设为私有,表示所有权不能转让。#include<iostream>using namespace std;template<class T>class ScopedPtr{public: ScopedPtr...转载 2018-03-14 21:49:55 · 344 阅读 · 0 评论 -
strtok实现
转自:http://blog.csdn.net/mormont/article/details/53677363#include "iostream"#include "algorithm"#include "map"using namespace std;char *strtok(char *str, const char *delim){ static char ...转载 2018-03-17 20:24:39 · 240 阅读 · 0 评论 -
运算符重载
#include "iostream"using namespace std;//必须提前声明,否则会报错class A;ostream& operator << (ostream &out, const A &a);istream& operator >> (istream &in, A &a);A operator + (const A &a1, const A &a2);class原创 2017-02-02 23:34:49 · 228 阅读 · 0 评论 -
C++---将二维数组作为参数
#include "iostream"using namespace std;void f(double *a, int r, int c){ for(int i=0; i<r; i++) for(int j=0; j<c; j++) cout << a[i*c+j] << " ";}int main(){ double a[2][3]原创 2017-01-20 11:28:37 · 397 阅读 · 0 评论 -
STL---获取某个文件夹下的所有txt文件,并进行处理
#include <iostream>#include <io.h> #include <string> #include <vector> #include "fstream"using namespace std; void getFiles( string, vector<string>& );int main() { vector原创 2016-10-08 10:24:41 · 1413 阅读 · 0 评论 -
STL---下一个排列
#include "iostream"#include "algorithm"using namespace std;int main(){ int a[3] = {3, 1, 2}; sort(a, a+3); //从小到大排序, 如果不排序,则得不到全部排列结果 do { for(int i=0; i<3; i++)原创 2016-03-04 16:22:18 · 423 阅读 · 0 评论 -
STL---string用法
#include "iostream"#include "vector"#include "string"#include "sstream"using namespace std;int main(){ string s = "aabcdef.txt"; cout << endl << "--------------------------find, rfind-------原创 2016-08-27 15:52:47 · 604 阅读 · 0 评论 -
STL---随机数发生器
#include <iostream> #include <stdlib.h> //rand() srand()#include <time.h> using namespace std;//产生[low, high)之间的随机数double randval(double low, double high) { double val; val = ((d原创 2016-03-05 12:13:13 · 1479 阅读 · 0 评论 -
STL---集合的运算
#include "iostream"#include "vector"#include "set"#include "string"#include "map"#include "algorithm"using namespace std;int main(){ int a[] = {1, 2}; int b[] = {2, 3}; vector<int> s1原创 2016-10-26 16:24:29 · 745 阅读 · 0 评论 -
STL---对于set中元素是否有序的探究
#include "iostream"#include "set"using namespace std;int main(){ set<int> s; s.insert(1); s.insert(3); s.insert(2); set<int>::iterator it; it = s.begin(); while(it != s.e原创 2016-03-04 17:48:28 · 3832 阅读 · 0 评论 -
STL---容器
vector 定义vector<int> v;vector<double> v;vector<STU> v; //存放结构体vector<int> v(5); //长度为5常用操作v[i]; //取值v.front(); //获取并返回首元素v.back(); //获取并返回尾元素v.push_back(x); //向尾部插入元素xv.siz原创 2016-03-04 16:08:35 · 367 阅读 · 0 评论 -
打印二维数组的新方法
#include "iostream"#include "vector"#include "algorithm"using namespace std;void myPrint(int *a, int row, int col){ for(int i=0; i<row; i++) { for(int j=0; j<col; j++) co原创 2016-10-04 17:41:05 · 608 阅读 · 0 评论 -
STL---按行读取数字串,并分割转为数字
t2.txt 效果 代码#include "iostream"#include "fstream"using namespace std;int main(){ ifstream fin; fin.open("t2.txt"); char str[100]; int N = 13; for(i=0; i<N; i++) { f原创 2016-03-06 15:31:20 · 693 阅读 · 0 评论 -
STL---获取某个文件夹下的文件
获取Debug目录下的txt文件#include <iostream>#include <io.h> #include <string> #include <vector> using namespace std; void getFiles( string, vector<string>& );int main() { vector<stri原创 2016-10-07 20:00:00 · 1035 阅读 · 0 评论 -
剑指offer---数据流中的中位数---大顶堆、小顶堆
题目描述 如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值。如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两个数的平均值。class Solution {public: vector<int> left; // 大顶堆 vector<int> right; // 小顶堆 ...原创 2018-03-11 22:28:38 · 556 阅读 · 0 评论