
C++程序设计
文章平均质量分 80
hooha
这个作者很懒,什么都没留下…
展开
-
《C++标准程序库》第二章摘录与笔记
《C++标准程序库》第二章,摘录与笔记2.2.1 模板所谓“template”,是针对“一个或多个尚未明确的型别”所撰写的函数或类别。使用template时,可以显示或者隐式地将型别当做参数来传递。template并非一次编译便生出适合所有型别的代码,而是针对被使用的某个(或某组)型别进行编译。这导致一个重要的问题:实际处理template时,面对函数模板,你必须先提供他的某个实作原创 2012-07-14 18:00:07 · 708 阅读 · 0 评论 -
Anagrams
AnagramsGiven an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.什么是anagrams?/** 整理的提交代码 * 处理复杂度为O(n),n是字符串个数,但是其中有排序等步骤没有固原创 2012-08-14 19:24:10 · 935 阅读 · 0 评论 -
Climbing Stairs
Climbing StairsYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?/** 整理的原创 2012-08-14 20:50:19 · 676 阅读 · 0 评论 -
《C++标准程序库》第五章摘录与笔记
《C++标准程序库》第五章摘录与笔记STL提供的六大组件:1、容器(containers):各种数据结构,用来存放数据,用来管理某类对象的集合。从实现的角度看,STL容器是一种class template。2、算法(algorithms):各种常用算法,用来处理群集内的元素。从实现的较短来看,STL算法是一种function template。3、迭代器(iterators):扮演原创 2012-07-31 15:02:07 · 1462 阅读 · 0 评论 -
拷贝构造函数形参规格
拷贝构造函数形参规格拷贝构造函数的形参基本都写为常量引用。#include using namespace std;class A{ public: A(int data = 0) : m_data(data) {} ~A() {} A(const A& other) { m_data= other.m_data; } void print() { co原创 2012-07-31 16:19:52 · 744 阅读 · 0 评论 -
赋值操作符重载函数形参规格
赋值操作符重载函数形参规格赋值操作符重载函数的形参基本都写为常量引用,返回值为引用。class A{ public: A(int data = 0) : m_data(data) {} ~A() {} A& operator=(const A& other) { if (this == &other) { return *this; } m_data原创 2012-08-01 15:08:43 · 1061 阅读 · 0 评论 -
Permutations
PermutationsGiven a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,原创 2012-08-23 00:36:52 · 848 阅读 · 0 评论 -
Combination Sum
Combination SumGiven a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be c原创 2012-08-23 01:45:34 · 8873 阅读 · 3 评论 -
Combination Sum II
Combination Sum IIGiven a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may on原创 2012-08-23 02:55:49 · 2466 阅读 · 0 评论 -
Add Two Numbers
Add Two NumbersYou are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers原创 2012-08-14 15:33:33 · 741 阅读 · 0 评论 -
4Sum
4SumGiven an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.No原创 2012-08-13 19:14:22 · 1715 阅读 · 0 评论 -
《C++标准程序库》第三章摘录与笔记
《C++标准程序库》第三章摘录与笔记3.2 头文件C++标准库在定义标准头文件时,对头文件扩展名进行了规范:根本没有扩展名。这种写法也适用于C标准头文件。但原来在C标准库中的头文件,必须采用前缀字符C,而不再是扩展名.h,在这些头文件中,每一个标识符都被声明在std命名空间中。这种命名方式的优点之一是可以区分旧头文件中的char* C函数,和新头文件中的标准C++ string类:原创 2012-07-14 22:40:24 · 557 阅读 · 0 评论 -
内存中的数据对齐
内存中的数据对齐先看个例子:#include struct { short sA; short sB; short sC;}A;struct { long lA; short sB;}B;struct { char chA; int iB; char chC;}C;struct { char chA; char chB; int iC;}D;s原创 2012-07-17 20:47:01 · 695 阅读 · 0 评论 -
《C++标准程序库》第六章摘录与笔记
《C++标准程序库》第六章摘录与笔记6.1 容器的共通能力和共通操作6.1.1 容器的共通能力1、所有容器提供的都是“value语意”而非“reference语意”。容器进行的元素的安插操作时,内部实施的是拷贝操作,置于容器内。一次STL容器的每一个元素都必须能够被拷贝。如果你打算存放的对象不具有public copy构造函数,或者你要的不是副本(如你要的是被多个容器共同容纳的元素原创 2012-08-04 12:16:45 · 840 阅读 · 0 评论 -
3Sum Closest
3Sum ClosestGiven an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each in原创 2012-08-13 14:07:06 · 3387 阅读 · 0 评论 -
3Sum
3SumGiven an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in原创 2012-08-12 17:16:56 · 6613 阅读 · 0 评论 -
Add Binary
Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100"./** 整理的提交代码 * 处理复杂度为O(max(n1,n2)) * 主要思路: * 1、先处理特殊情况,有其中一个为空,则原创 2012-08-13 23:33:01 · 2210 阅读 · 0 评论 -
《C++标准程序库》第四章摘录与笔记
《C++标准程序库》第四章摘录与笔记4.1 Pairs(对组)类pair可以将两个对象视为一个对象。容器类别map和multimap使用pairs来管理器键/值对。任何函数需返回两个值,也需要pair。4.2 Class auto_ptrC++标准程序库提供的auto_ptr是“一种”智能指针,帮助程序员防止“被异常抛出时发生资源泄露”。auto_ptr只是针对特定问题而设计的原创 2012-07-28 18:08:12 · 437 阅读 · 0 评论 -
C++类对象布局
#include using namespace std;// 多重继承构造执行顺序:// 1、首先执行虚基类的构造函数,多个虚基类的构造函数按照被继承的顺序构造;// 2、执行基类的构造函数,多个基类的构造函数按照被继承的顺序构造;// 3、执行成员对象的构造函数,多个成员对象的构造函数按照申明的顺序构造;// 4、执行派生类自己的构造函数;// 5、析构以与构造相反的顺序执行;原创 2012-04-08 23:11:33 · 522 阅读 · 0 评论