2016年1月1日

快速排序算法(Quicksort)

摘要: 快速排序算法是对集合中元素进行排序最通用的算法,俗称快排,其算法的时间复杂度为O(nlgn),空间复杂度为O(1)。我们举例来对其算法思路进行理解,譬如数组 A = { 4, 8, 1, 2, 9, 7, 3, 0, 5, 6 };第一步,以最后一个数6为基准,把小于等于6的数挪到数组左边,把大于6... 阅读全文

posted @ 2016-01-01 08:13 NULL00 阅读(5256) 评论(0) 推荐(1) 编辑

2013年6月4日

C++ Primer 读书笔记 - 第十五章

摘要: 1. OOP基于三个基本概念 - data abstraction,inheritance,dynamic binding. 其关键思想是多态性(polymorphism)。2. 定义为virtual的函数是基类期待派生类重新定义的,基类希望派生类继承的函数不能定义为虚函数。3. virtual关键字只能出现在类体内的声明中,不能出现在类体外的定义中。4. 派生类只能通过派生类对象访问其基类的protected成员,派生类对其基类类型对象的protected成员没有特殊访问权限。void Bulk_item::memfcn(const Bulk_item &d, const Item_ 阅读全文

posted @ 2013-06-04 02:36 NULL00 阅读(1726) 评论(0) 推荐(1) 编辑

2013年6月2日

C++ Primer 读书笔记 - 第十四章

摘要: 1. An overloaded operator must have at least one operand of class or enumeration type.2. Default arguments for overloaded operators are illegal, except for operator(), the function-call operator.3. The assignment (=), subscript ([]), call (()), and member access arrow (->) operators must be defin 阅读全文

posted @ 2013-06-02 00:59 NULL00 阅读(663) 评论(0) 推荐(0) 编辑

2013年5月31日

C++ Primer 读书笔记 - 第十三章

摘要: 1. Initialization和Assignment不一样。其中Initialization包括direct-initialization (如A a(...))和copy-initialization (如 A a = b;) 注意A a = b为copy-initialization, 而A a; A b; a = b;为Assignment。2. We cannot copy objects of the IO types, so we cannot use copy-initialization on objects of these types.3. As the copy .. 阅读全文

posted @ 2013-05-31 03:36 NULL00 阅读(435) 评论(0) 推荐(1) 编辑

2013年5月30日

C++ Primer 读书笔记 - 第十二章

摘要: 1. 类中成员默认属性为private,private成员只对类里面的其他成员可见。2. 在类里面定义的成员函数默认为inline函数。如果只是在类中声明,那么其定义也要有inline关键字,inline关键字在声明和定义处任意出现一次就行。inline函数的定义必须出现在头文件中。3. 声明为const的成员函数不能改变调用它的对象的数据成员,const在声明和定义中都要写明。4. data abstraction是指我们只知道接口(interface),不知道内部如何实现(implementation)。5. encapsulation是指将低层次的元素组装成高层次的实体。例如一个函数,一 阅读全文

posted @ 2013-05-30 11:04 NULL00 阅读(533) 评论(0) 推荐(1) 编辑

2013年5月29日

C++ Primer 读书笔记 - 第十一章

摘要: #include <algorithm>1. find()函数2. accumulate()函数3. find_first_of()函数的两个range的类型可以不同,但是两个range内部的类型必须相同。4. fill()函数,使用时必须保证空间是足够的。 fill_n(back_inserter(vec), 10, 0);//appends 10 elements to vec5. replace()函数改变容器内部,replace_copy()函数不改变容器内部,而是自己新拷贝一份。6. sort()函数,unique()函数,unique_copy()函数,stable_s 阅读全文

posted @ 2013-05-29 07:06 NULL00 阅读(757) 评论(0) 推荐(0) 编辑

2013年5月28日

C++ Primer 读书笔记 - 第十章

摘要: 1. map和set中的key是唯一的,multimap和multiset中的key可以出现多次。2. Whenever we use an associative container, its keys have not only a type, but also an associated comparsion function.3. The value_type is a pair and that we can chagne the value but not the key member of that pair.4. 用下标插入元素时,内部操作是这样的: - 找key,找不到 .. 阅读全文

posted @ 2013-05-28 09:23 NULL00 阅读(520) 评论(0) 推荐(0) 编辑

C++ Primer 读书笔记 - 第九章

摘要: 1. Two constraints that element types must meet: - The element type must support assignment. - We must be able to copy objects of the element type. Soreferences, IO library types, auto_ptr typeare not permitted.2. Only vector and deque support iterator arithmetic and the use of relational operato... 阅读全文

posted @ 2013-05-28 02:41 NULL00 阅读(482) 评论(1) 推荐(0) 编辑

2013年5月27日

C++ Primer 读书笔记 - 第八章

摘要: 1. IO library types do not allow copy or assignment. Only element types that support copy can be stored in vectors or other container types. We cannot have a parameter or return type that is one of the stream types. If we need to pass or return an IO object, it must be passed or returned as a poin.. 阅读全文

posted @ 2013-05-27 06:58 NULL00 阅读(557) 评论(0) 推荐(0) 编辑

2013年5月26日

C++ Primer 读书笔记 - 第七章

摘要: 1. To invoke a function we use the call operator, which is a pair of parentheses. The operands to the call operator are the name of the function and a (possibly empty) comma-separated list of arguments.#include <iostream>using namespace std;string::size_type find_char(const string &s, char 阅读全文

posted @ 2013-05-26 12:11 NULL00 阅读(438) 评论(0) 推荐(0) 编辑

2013年5月25日

C++ Primer 读书笔记 - 第六章

摘要: 这一章讲控制结构,和C,Java没区别。跟C不同的是,C++增加了try blocks and Exception Handling#include <iostream>#include <stdexcept>using namespace std;void foo(){ int b = 0; if (b == 0) throw runtime_error("b == 0"); int a = 4/b; cout << a << endl;}void bar() throw(int){ throw 5;}int main(){ 阅读全文

posted @ 2013-05-25 03:59 NULL00 阅读(435) 评论(0) 推荐(0) 编辑

2013年5月20日

C++ Primer 读书笔记 - 第五章

摘要: 这一章的内容和C语言基础知识大同小异。1. i++ 与 ++i 的效率问题 i++的话,需要保存原来的值,然后增加 i,之后返回 i 原来的值;++i 直接增加 i,然后返回当前的 i 值,所以少做一步工作。2. Setting the pointer to 0 after the object it refers to has been deleted makes it clear that the pointer points to no object. It is legal to delete a pointer whose value is zero; doing so has .. 阅读全文

posted @ 2013-05-20 10:01 NULL00 阅读(352) 评论(0) 推荐(0) 编辑

C++ Primer 读书笔记 - 第四章

摘要: 这一章更多的是在讲C语言的东西。Pointers to const Objectsconst double *ptrconst Pointersdouble *const ptr = &value //必须初始化const Pointer to a const Objectcosnt double *const ptr = &valuePointers and TypedefsTypedef string *pstringconst pstring cstr;其实const pstring cstr 等价于 string *const cstrconst int *pci_ok 阅读全文

posted @ 2013-05-20 04:11 NULL00 阅读(394) 评论(0) 推荐(1) 编辑

2013年5月19日

C++ Primer 读书笔记 - 第三章

摘要: 1. std::string size()函数返回值为string::size_type,用下标时,也用string::size_type作为index的类型#include <iostream>#include <cstdio>#include <string>using namespace std;int main(){ string s = "abc"; cout << s << endl; cin >> s; cout << s << endl; string line; 阅读全文

posted @ 2013-05-19 13:01 NULL00 阅读(394) 评论(0) 推荐(0) 编辑

C++ Primer 读书笔记 - 第二章

摘要: 1. 这章谈到了初始化和赋值其实是不同的,这使我想起了构造函数中的普通构造函数,拷贝构造函数,赋值构造函数,详见博文C++中的构造函数与析构函数 string这个类有default constructor,即初始化为"".2. 一个变量在一个程序中能够声明多次,但只能定义一次。3. Nonconst varialbes are extern by default. To make a const variable accessible to other files we must explicitly specify that it is extern.4. There i 阅读全文

posted @ 2013-05-19 10:27 NULL00 阅读(505) 评论(0) 推荐(0) 编辑

导航