12 2018 档案

摘要:#include #include #include #include #include using namespace std; int main() { stack> s; queue> q; // the default container of queue is deque for (int i = 0; i < 10; i++) { ... 阅读全文
posted @ 2018-12-28 06:42 super行者
摘要:Vector: 动态数组,内存中一整块连续区域。支持.reserve()和.capacity()。为提高效率,最好在添加元素之前用.reserve()分配好容量。插入删除操作越靠近数组首部效率越低。 deque(double ended queue): 动态数组,内存中多段连续区域拼凑。不支持res 阅读全文
posted @ 2018-12-28 05:13 super行者
摘要:#include #include #include using namespace std; template bool decreOrder(T &a, T &b) { return (a bool increOrder(T &a, T &b) { return (a > b); } template void Sort(vector & v, bool (*... 阅读全文
posted @ 2018-12-27 05:36 super行者
摘要:参考本博客中链接 《C++ vector 删除符合条件的元素》 阅读全文
posted @ 2018-12-27 04:45 super行者
摘要:#include using namespace std; template bool increSort(T &a, T &b) { return (a > b); } template bool decreSort(T &a, T &b) { return (a void Sort(T* array, int len, bool(*compare)(T&, T&)) ... 阅读全文
posted @ 2018-12-25 07:39 super行者
摘要:#include #include using namespace std; template class Stack { public: Stack() { } ~Stack() { } void push(T &e) { m_list.push_front(e); } void pop()... 阅读全文
posted @ 2018-12-25 06:37 super行者
摘要:#!/usr/bin/python import xml.etree.ElementTree as etree tree = etree.parse(wordbook.xml')root = tree.getroot()print len(root) entries = tree.findall(' 阅读全文
posted @ 2018-12-23 19:36 super行者
摘要:看这篇帖子的,我想都是电子爱好者或电类专业学生。不知道大家都处于什么一个阶段,这篇帖子是写给入门者的,要解决一个问题:初学者应重点掌握什么电子知识,大学阶段如何学习? 先说点貌似题外的东西——3个谬论。 谬论一:高中老师常对我们说,大家现在好好学,考上了大学就轻松了,爱怎么玩怎么玩。这真是狗屁。别的 阅读全文
posted @ 2018-12-23 19:27 super行者
摘要:#include #include using namespace std; // rever letters of a string char * strRevert1 (char * src) { if (src == NULL) return NULL; int len = strlen(src); for (int i=0; i= pWord); ... 阅读全文
posted @ 2018-12-23 19:19 super行者
摘要:#include using namespace std; unsigned int strlen1(const char * str) { const char * p = str; while (*p++ != '\0'); return (p-1-str); } int main() { char a[] = "12345"; cout << st... 阅读全文
posted @ 2018-12-23 19:19 super行者
摘要:#include #include using namespace std; bool checkRevStr (const char * src) { if (src == NULL) return false; const char * end = src + strlen(src) - 1; while (*src++ == *end--); retur... 阅读全文
posted @ 2018-12-23 19:18 super行者
摘要:#include #include using namespace std; int strcmp1 (const char * a, const char * b) { int ret = 0; while (!(ret=*a-*b) && *b) { ++a; ++b; } return (ret>0)?(1):((... 阅读全文
posted @ 2018-12-23 19:17 super行者
摘要:#include #include using namespace std; const char * findFirstLongestStr (const char * src, const char * des, unsigned int & count) { if (src==NULL || des==NULL) return NULL; int desLen = st... 阅读全文
posted @ 2018-12-23 19:16 super行者
摘要:例如字符串aabbbc,插入字符个数后变成aa2bbb3c1 阅读全文
posted @ 2018-12-23 19:15 super行者
摘要:#include #include using namespace std; void printBit (unsigned int value) { unsigned int bits = sizeof(unsigned int) * 8; stringstream s; for (int i=0; i> bits-1-i; s > (bits-1-... 阅读全文
posted @ 2018-12-23 19:15 super行者
摘要:1. 把字母替换成它后面的第4个字母。如:a->e, A->E, X->b, y->c 2. 翻转整个字符串 阅读全文
posted @ 2018-12-23 19:14 super行者
摘要:empty() 堆栈为空则返回真 pop() 移除栈顶元素 push() 在栈顶增加元素 size() 返回栈中元素数目 top() 返回栈顶元素 阅读全文
posted @ 2018-12-23 19:13 super行者
摘要:include #include using namespace std; bool strToInt (char * strIn, int * valueOut) { if ((strIn==NULL) || (valueOut==NULL)) { return false; } bool status = false; int v... 阅读全文
posted @ 2018-12-23 19:12 super行者
摘要:#include using namespace std; char * strcpy1 (char * strDest, char * strSrc) { if ((strDest==NULL) || (strSrc==NULL)) { return NULL; } char * strDeskCpy = strDest; while ... 阅读全文
posted @ 2018-12-23 19:11 super行者
摘要:#include #include using namespace std; void * memcpy1 (void * desAddr, const void * srcAddr, unsigned int count) { assert ((desAddr!=NULL) && (srcAddr!=NULL)); char * from = NULL; char ... 阅读全文
posted @ 2018-12-23 19:10 super行者
摘要:#include #include #include using namespace std; const char * strstr1 (const char * src, const char * des) { assert ((src!=NULL)&&(des!=NULL)); int srcLen = strlen(src); int desLen = st... 阅读全文
posted @ 2018-12-23 19:09 super行者 阅读(217) 评论(0) 推荐(0)
摘要:#include #include #include using namespace std; char * revStrExcludeSub (char * src, char * sub) { if ((src==NULL) || (sub==NULL)) return NULL; char * head=src, * tail=src, * pSub=sub; ... 阅读全文
posted @ 2018-12-23 19:08 super行者
摘要:#include #include using namespace std; char * revStr (char * src, int len) { if (len <= 1) return src; *src ^= *(src+len-1); *(src+len-1) ^= *src; *src ^= *(src+len-1); return (... 阅读全文
posted @ 2018-12-23 19:07 super行者
摘要:#include #include #include using namespace std; int validateInt (const char * src) { if (src == NULL) return 0; const char * p = src; while (*p>='0' && *p st; while (pA >= a) {... 阅读全文
posted @ 2018-12-23 19:06 super行者
摘要:#include #include using namespace std; // not using string library char * rightLoop1 (char * src, int n) { if (src==NULL) return NULL; char * p = src; while (*p++); int len = p-1-sr... 阅读全文
posted @ 2018-12-23 19:05 super行者
摘要:#include #include using namespace std; // pos starting from 0 char * deleteChars1 (char * src, int pos, int len) { if ((src==NULL) || (posp) || (src+pos+len-1>p)) return NULL; memcpy (src+p... 阅读全文
posted @ 2018-12-23 19:04 super行者
摘要:将字符串分成两部分,前半部分按ASCII码升序排序,后半部分不变(如果字符串是奇数个,则中间的字符不变)再将前后两部分交换,最后将该字符串输出。 阅读全文
posted @ 2018-12-23 19:02 super行者
摘要:#include #include using namespace std; char * deleteChar (char * src, char c) { if (src == NULL) return NULL; char * p = src; char * head = src; while (*p != '\0') { if ... 阅读全文
posted @ 2018-12-23 19:01 super行者
摘要:#include <iostream>#include <string.h>using namespace std;char * strcat1 (char * dest, char * src){ if ((dest==NULL) || (src==NULL)) return NULL; char 阅读全文
posted @ 2018-12-23 19:00 super行者
摘要:汉字作为一个字符处理,已知:汉字编码为双字节,其中首字节<0,尾字节在0~63以外(如果一个字节是 -128 ~ 127) 阅读全文
posted @ 2018-12-23 18:59 super行者
摘要:#include #include using namespace std; void calculate (const char * src, int * max0, int * max1) { if (src == NULL) return; int tmpCnt=1; *max0 = 1; *max1 = 1; while (*src++) ... 阅读全文
posted @ 2018-12-23 18:58 super行者
摘要:#include #include using namespace std; char * replace (char * in, char * s1, char * s2, char *out) { if ((in==NULL)||(s1==NULL)||(s2==NULL)||(out==NULL)) return NULL; char *pOut = out; ... 阅读全文
posted @ 2018-12-23 18:57 super行者
摘要:#include #include using namespace std; #define BIT(n) (0x1 T set_bit (T value, T bit_n) { value |= BIT(bit_n); return value; } template T clear_bit (T value, T bit_n) { value &= ~BIT(b... 阅读全文
posted @ 2018-12-23 18:56 super行者
摘要:#include #include using namespace std; #define BIT(n) (0x1=0; i--) { if (c & BIT(i)) cout << "1"; else cout << "0"; } cout <<"b" << endl; } int m... 阅读全文
posted @ 2018-12-23 18:55 super行者
摘要:#include #include using namespace std; bool checkLittleEnd (void) { union test { int a; char b; } t; t.a = 1; return (t.b==1); } int main() { if (checkLittle... 阅读全文
posted @ 2018-12-23 18:53 super行者
摘要:【自我总结】 1.默认构造函数不仅可以是无参的,也可以是有参的,但所有参数必须指定默认值。一个类只能有一个默认构造函数。 2.什么时候调用默认构造函数? a.声明类的对象时没有括号时。如:classA objA; b.子类构造函数没有显式调用父类构造函数时 3.构造函数中的默认参数要从右向左指定。 阅读全文
posted @ 2018-12-23 18:49 super行者
摘要:#include #include using namespace std; class demo { public: static int i; // 这里不可以初始化非const static变量! static const int j = 1; // 1st place to initiate for const static varia... 阅读全文
posted @ 2018-12-23 18:48 super行者
摘要:#include #include using namespace std; class demo { public: static void showObjCount(void); private: static int count; static const int j = 1; public: void funcObj(void); demo(i... 阅读全文
posted @ 2018-12-23 18:47 super行者
摘要:class EMPTY { public: EMPTY(); //默认构造函数 EMPTY(const EMPTY &); //复制构造函数 ~EMPTY();//默认析构函数 EMPTY & operator=(const EMTPY &); //赋值运算符 EMPTY * operator&(); //取址运算符 const EMPTY * ... 阅读全文
posted @ 2018-12-23 18:46 super行者
摘要:普通构造函数可以被隐式调用,而explicit构造函数(显式构造函数)只能被显式调用 关于隐式转换,参考:【转】这篇文章 首先, C++中的explicit关键字只能用于修饰只有一个参数的类构造函数, 它的作用是表明该构造函数是显示的, 而非隐式的, 跟它相对应的另一个关键字是implicit, 意 阅读全文
posted @ 2018-12-23 18:44 super行者
摘要:复制构造函数应用场景: 1.一个对象以值传递的方式传入函数体 2.一个对象以值传递方式从函数返回 3.一个对象需要通过另外一个对象进行初始化 阅读全文
posted @ 2018-12-23 18:42 super行者
摘要:如果复制的对象中引用了某个外部的内容(例如分配在堆上的数据),那么在复制这个对象的时候,让新旧两个对象指向同一个外部的内容,就是浅复制;如果在复制这个对象的时候为新对象制作了外部对象的独立的COPY,就是深复制。 深拷贝和浅拷贝主要是针对类中的指针和动态分配的空间来说的,因为对于指针只是简单的值复制 阅读全文
posted @ 2018-12-23 18:40 super行者
摘要:A & operator= (A & b) {} A obj1; A obj2(1,2); obj1 = obj2; //这条赋值语句可理解如下: obj1.=(obj2) , 相当于obj1调用了它自己的=(A &b) 函数, 而=就是函数名。 因此obj1=obj2这句函数调用本身是有返回值的, 阅读全文
posted @ 2018-12-23 18:36 super行者
摘要:全部模板特例化 模板中所有参数全被指定为确定的类型 部分模板特例化分两种情况 1.对部分模板参数进行特例化 2.使用具有某一特征的类型,对模板参数进行特例化 混合这两种情况的例子如下 总结: template后<>的列表中要列出没有明确指明类型的 typename 下面是一段示例代码: 下面是另一段 阅读全文
posted @ 2018-12-23 17:17 super行者
摘要:下面代码展示通过继承方式把模板中与参数无关的代码分离出来 阅读全文
posted @ 2018-12-23 10:44 super行者
摘要:#include using namespace std; class Shape { public: virtual void display(void) = 0; virtual void setValue(void) = 0; }; class Circle: public Shape { public: Circle(int x=1):radius(x){... 阅读全文
posted @ 2018-12-20 22:02 super行者
摘要:代码中Author和Singer以virtual方式继承Person,解决了Author_Singer实例拥有两份Person copy的问题,这是一种解决方法。 另一种方法是明确指定引用的子类:pp.Author::eat(); 下面代码显示了,使用和不使用virtual来继承基类时,各个类的构造 阅读全文
posted @ 2018-12-19 21:40 super行者
摘要:1.如何在预处理阶段计算sizeof? 阅读全文
posted @ 2018-12-18 06:29 super行者
摘要:#include #include using namespace std; class Person { public: virtual void print(void) { cout << "I am a Person!" << endl; } }; class Chinese: public Person { public: virt... 阅读全文
posted @ 2018-12-18 05:26 super行者
摘要:下面代码显示了不同调用虚函数时的实际执行情况: 执行结果为: 阅读全文
posted @ 2018-12-18 05:17 super行者
摘要:#include #include using namespace std; class String { public: String(const char * x=NULL); String(const String & x); ~String(); String & operator= (const String & x); Stri... 阅读全文
posted @ 2018-12-15 13:43 super行者
摘要:下面代码侧面说明,编译器在构造函数末尾处初始化vptr。所以如果在构造函数中调用virtual函数,动态绑定不会起作用,只会调用本类中的virtual函数: 下面代码是我自己写的读取虚函数表示例: 屏幕输出: 如果将 改为 class Base{ public: virtual void func0 阅读全文
posted @ 2018-12-13 20:45 super行者
摘要:#include #include using namespace std; class MyString { public: MyString(const char * s=NULL) { if (s == NULL) { m_string = new char[1]; m_string[... 阅读全文
posted @ 2018-12-13 06:24 super行者
摘要:[转自]https://blog.csdn.net/geophyboy/article/details/14119775 问题(知识点)描述:a. 在C++的类的成员函数中,允许直接访问该类的对象的私有成员变量。b. 在类的成员函数中可以访问同类型实例的私有变量。c. 拷贝构造函数里,可以直接访问另 阅读全文
posted @ 2018-12-13 05:40 super行者
摘要:[转自] https://blog.csdn.net/ipmux/article/details/45038869 Overload、Override和Overwrite英文接近,比较容易混淆,再加上翻译五花八门,使用时张冠李戴,往往是今天清楚明天糊涂。这三个概念在前面章节已分别讨论,这里再集中比较 阅读全文
posted @ 2018-12-12 21:10 super行者
摘要:同一个作用域内,可以声明几个功能类似的同名函数,但是这些同名函数的形式参数(指参数的个数、类型或者顺序)必须不同。您不能仅通过返回类型的不同来重载函数。 阅读全文
posted @ 2018-12-12 20:35 super行者
摘要:引用:https://www.cnblogs.com/burellow/archive/2011/05/25/2056506.html 1) 虚函数是动态绑定的,也就是说,使用虚函数的指针和引用能够正确找到实际类的对应函数,而不是执行定义类的函数。这是虚函数的基本功能,就不再解释了。 2) 构造函数 阅读全文
posted @ 2018-12-11 22:34 super行者
摘要:只有虚函数才使用动态绑定,其它全部是静态绑定 编译阶段决定:non-virtual 函数->静态绑定->绑定静态类型 运行时决定: virtual 函数->动态绑定->绑定动态类型 虚函数是动态绑定的,但是为了执行效率,缺省参数是静态绑定的。永远记住: “绝不重新定义继承而来的缺省参数(Never 阅读全文
posted @ 2018-12-11 22:04 super行者
摘要:1.在C++中,只要不明确指定是public,默认是private 2.virtual关键字主要是实现动态绑定。要触发动态绑定,必须满足两个条件: 第一,指定为虚函数; 第二,通过基类类型的引用或指针调用。 只要基函数定义了virtual,继承类的该函数也就具有virtual属性 纯虚函数为后代类提 阅读全文
posted @ 2018-12-10 21:20 super行者
摘要:上面main()函数执行后的输出为: Normal Contructor: 1 Normal Contructor: 2 end of program Destructor: 2 Destructor: 1 阅读全文
posted @ 2018-12-10 21:00 super行者
摘要:#include #include using namespace std; class String { public: String(const char * str=NULL) { if (str == NULL) { //这两行代码保证了: //任一String对象的m_string都不... 阅读全文
posted @ 2018-12-09 22:16 super行者