随笔分类 - C++程序设计
记录下学习的点滴
摘要:#include <iostream> #include <vector> #include <cstddef> #include <string> #include <sstream> #include <fstream> #include <algorithm> #include <cmath>
阅读全文
摘要:template <class T> double VectorMedian(std::vector<T> &In) { std::sort(In.begin(), In.end()); if(In.size() % 2 == 0) { return 0.5*(In.at(In.size()/2)+
阅读全文
摘要:#include <iostream> #include <string> #include <vector> #include <algorithm> #include <map> #include <fstream> #include <sstream> void ReadDataFromFil
阅读全文
摘要:template <class T1, class T2> double Minkowski(const std::vector<T1> &inst1, const std::vector<T2> &inst2, const double &k) { if(inst1.size() != inst2
阅读全文
摘要:#include <iostream> #include <vector> #include <string> #include <sstream> #include <fstream> #include <algorithm> #include <functional> #include <num
阅读全文
摘要:原始数据 #include <iostream>#include <fstream>#include <sstream>#include <vector>#include <string>#include <algorithm>#include <numeric>#include <cmath>#i
阅读全文
摘要:Pseudo Code of KNN We can implement a KNN model by following the below steps: Load the data Initialise the value of k For getting the predicted class,
阅读全文
摘要:比如输入是192.168.80.12-15,解析成192.168.80.12、192.168.80.13、192.168.80.14、192.168.80.15; 亦或192.168.10.10-192.168.10.12,解析成192.168.10.10、192.168.10.11、192.168
阅读全文
摘要:template <class DataType>void ProcessMap(std::map<std::string, std::vector<DataType> > &mymapa, std::map<std::string, std::vector<DataType> > &mymapb)
阅读全文
摘要:#include <iostream>#include <vector>#include <string> class Assoc { struct Pair { std::string name; double val; Pair(std::string n="", double v=0) :na
阅读全文
摘要:#include <iostream> class Singleton { static Singleton s; int i; Singleton(int x):i(x) {} Singleton& operator=(Singleton&); Singleton(const Singleton&
阅读全文
摘要:复制构造函数与复制赋值的区别如下: class Name { const char* s; //... }; class Table { Name* p; size_t sz; public: //... Table(const Table&); //复制构造函数 Table& operator=(
阅读全文
摘要:关联数组是用户定义类型中最常见的也是最有用的一类。关联数组也常被成为映射(map),有时被 成为字典(dictionary),其中保存的是值的对偶。给定了一个称为关键码的值,我们就能访问另一个 称为映射值的值。可以将关联数组想象为一个下标不必是整数的数组: template<class K, cla
阅读全文
摘要:#include <sys/stat.h> int stat(const char *restrict pathname, struct stat *restrict buf); struct stat { mode_t st_mode; /*file type & mode(permissions
阅读全文
摘要:template <class T1, class T2> struct std::pair { typedef T1 first_type; typedef T2 second_type; T1 first; T2 second; pair() :first(T1()), second(T2())
阅读全文
摘要:#include <functional> template <class T1, class T2, class T3>void outer_product(std::vector<T1> &inst1, std::vector<T2> &inst2, std::vector<std::vecto
阅读全文
摘要:template <class T1, class T2>double Pearson(std::vector<T1> &inst1, std::vector<T2> &inst2) { if(inst1.size() != inst2.size()) { std::cout<<"the size
阅读全文
摘要:#include <iostream>#include <vector>#include <numeric> int main() { double a[]={1, 3, 5.4}; double b[]={1, 5, 7}; std::vector<double> v_a, v_b; for(si
阅读全文
摘要:#include <string>#include <iostream>#include <stack> int main() { std::string str="hello"; std::stack<char> reverse_str; std::cout<<str<<std::endl; fo
阅读全文
摘要:#include <iostream>#include <fstream>#include <vector>#include <string> int main() { std::vector<std::string> v_ip; v_ip.clear(); v_ip.push_back("192.
阅读全文