自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(42)
  • 收藏
  • 关注

原创 move构造函数,move赋值函数

要求:ContainersIn this workshop, you code a container class that holds notifications and a class that holds separate messages.LEARNING OUTCOMESUpon successful completion of this workshop, you w

2015-10-21 17:59:17 1660

原创 list对象作为类的私有成员时分配内存

今天在做国外题目时,碰到了一个问题,就是LVList类的私有成员中包含list对象,如果直接声明对象,不分配内存的话,后面对其访问就会报错。最开始时,我是这样声明的:templateclass KVList{public: KVList(); size_t size() const; //return number of key-value const K& key(int

2015-10-18 23:42:24 407

原创 类模板带参数,list,pair

要求:TemplatesIn this workshop, you design and code a class template and test it on two different classes.LEARNING OUTCOMESUpon successful completion of this workshop, you will have demonstrated

2015-10-18 23:33:03 585

原创 leetcode 39:Combination Sum

题目:Given 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 chosen from C unlim

2015-10-18 17:04:36 255

原创 leetcode 38:Count and Say

题目:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is rea

2015-10-18 16:42:27 259

原创 leetcode 37:Sudoku Solver

题目:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.

2015-10-18 16:37:10 201

原创 leetcode 36:Valid Sudoku

题目:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partia

2015-10-17 23:14:10 350

原创 leetcode 35:Search Insert Position

题目:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in t

2015-10-17 22:08:52 242

原创 leetcode 34:

题目:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is n

2015-10-17 20:40:24 281

原创 leetcode 33:Revised Binary Search

题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the ar

2015-10-17 17:33:22 322

原创 leetcode 32:Longest Valid Parentheses

题目:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is

2015-10-17 15:57:23 274

原创 linux下简单聊天室(未完待更新)

学了网络编程,一直想来练练手,于是决定自动动手来完成一个linux下简单聊天室的项目,本着由浅入深的原则,我会先从最简单的功能开始,然后逐渐增加其他功能。由于本人对QT的网络编程块还不熟悉,所以不会对界面进行设计。涉及内容:TCP/IP通信 多线程

2015-10-16 22:16:09 466

原创 leetcode31:Next Permutation

题目:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest

2015-10-16 14:07:07 342

原创 关于指针的引用

今天在做任务时,需要将数据从文本中读出来,并且动态的存到二叉搜索树中,刚开始的做法如下:void StockTree::insertNode(StockNode *p,StockNode *newNode){ if(p==NULL) { StockNode *temp=new StockNode(newNode->getStock(),NULL,NULL); p=temp; }

2015-10-16 09:40:59 286

原创 Error C2662, cannot convert ‘this’ pointer from ‘const class ’ to ‘class &’

class StockNode{ friend class StockTree;private: Stock myStock; StockNode *left; StockNode *right;public: StockNode(); StockNode(Stock s,StockNode* l,StockNode *r):myStock(s),left(l),right(r)

2015-10-16 09:17:24 335

原创 leetcode 29:Divide Two Integers

题目:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution {public: int divide(int dividend, int divisor) {

2015-10-13 16:49:32 255

原创 leetcode 28:Implement strStr()

题目:Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.思路:题目大意是让我们找到needle字符串在haystack字符串中第一次出现的位置。这就是字符串的模式匹配问题。朴素的模式匹配算法是对主串的每一

2015-10-12 20:38:39 217

原创 KMP算法

KMP算法应该是每一本《数据结构》书都会讲的,算是知名度最高的算法之一了,但很可惜,我大二那年压根就没看懂过~~~之后也在很多地方也都经常看到讲解KMP算法的文章,看久了好像也知道是怎么一回事,但总感觉有些地方自己还是没有完全懂明白。这两天花了点时间总结一下,有点小体会,我希望可以通过我自己的语言来把这个算法的一些细节梳理清楚,也算是考验一下自己有真正理解这个算法。 什么是

2015-10-12 19:07:32 317

原创 leetcode 27:Remove Element

题目:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new len

2015-10-12 16:15:33 277

原创 leetcode 26:Remove Duplicates from Sorted Array

题目:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in p

2015-10-12 15:46:38 220

原创 leetcode 25:Reverse Nodes in k-Group(15-10-11)

题目:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain

2015-10-11 19:20:40 250

原创 leetcode 24:Swap Nodes in Pairs(15-10-11)

题目:Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant s

2015-10-11 10:26:33 313

原创 回溯与DFS

背景:有时会遇到这样一类题目,它的问题可以分解,但是又不能得出明确的动态规划或是递归解法,此时可以考虑用回溯法解决此类问题。回溯法的优点 在于其程序结构明确,可读性强,易于理解,而且通过对问题的分析可以大大提高运行效率。但是,对于可以得出明显的递推公式迭代求解的问题,还是不要用回溯 法,因为它花费的时间比较长。 回溯法中,首先需要明确下面三个概念:(一)约束函数:约束函

2015-10-11 09:45:52 1429

转载 操作系统

目录:1. 进程的有哪几种状态,状态转换图,及导致转换的事件。2. 进程与线程的区别。3. 进程通信的几种方式。4. 线程同步几种方式。5. 线程的实现方式. (用户线程与内核线程的区别)6. 用户态和核心态的区别。7. 用户栈和内核栈的区别。8. 内存池、进程池、线程池。9. 死锁的概念,导致死锁的原因,导致死锁的四个必要条

2015-10-11 08:44:50 379

原创 leetcode 23:Merge k Sorted Lists(15-10-10)

题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListN

2015-10-10 23:04:10 248

原创 leetcode 22:Generate Parentheses(15-10-9)

题目:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(()

2015-10-08 22:33:24 256

原创 leetcode 21:Merge Two Sorted Lists(15-10-9)

一.题目Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.结点定义如下: struct ListNode { int val;

2015-10-08 21:39:01 230

原创 leetcode 20:Valid Parentheses(15-10-8)

题目:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are

2015-10-08 21:01:13 218

原创 leetcode 19:Remove Nth Node From End of List(15-10-7)

一.题目Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the

2015-10-08 20:25:03 204

原创 leetcode18:4Sum(15-10-6)

一.题目Given 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.Note:

2015-10-07 23:41:20 207

原创 leetcode 17:Letter Combinations of a Phone Number(15-10-5)

1.ProblemGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.I

2015-10-05 19:35:14 336

转载 boost之scoped_array的使用

boost库是一个有着工业级强度的C++库,开源而且完全免费,有着C++准标准库的美誉,下面说一下boost库里的scoped_array使用方法.scoped_array使用起来很方便,轻巧,而且速度和原始指针相差无几. 而且更加安全..scoped_array主要有以下几个特点;1.构造函数接受的的指针必须是new[]返回的结果,而不能是new返回的结果.

2015-10-05 16:58:14 638

原创 条款35(考虑virtual函数以外的其他选择)之Template Method模式和Strategy模式

Strategy策略模式作用:定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户。UML图:Strategy模式将逻辑(算法)封装到一个类(Context)里面,通过组合的方式将具体算法的实现在组合对象中实现,再通过委托的方式将抽象接口的实现委托给组合对象实现将算法的逻辑抽象接口(DoAction)封装到一

2015-10-04 22:28:22 371

原创 条款35(考虑virtual函数以外的其他选择)之Template Method模式

看来有必要先看看设计模式了。。。。。。。Template模板方法模式作用:定义一个操作中的算法的骨架。而将一些步骤延迟到子类中,模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。其关键是将通用算法(逻辑)封装在抽象基类中,并将不同的算法细节放到子类中实现。AbstractClass是抽象类,其实也就是一个抽象模板,定义并实现了一个模板方法。

2015-10-04 22:09:35 316

原创 条款31提及pimpl设计模式

条款31(将文件间的编译依存关系降至最低)中提到,由于头文件和其含入头文件之间形成一种编译依存关系,如果这些头文件所依赖的其他头文件有任何改变,那么每一个含入该头文件的的文件就要重新编译。为了减少这种依赖关系,文中提到一种“将对象实现细目隐藏于一个指针背后”的游戏。针对Person我们可以:把Person分割为两个classes,一个只提供接口,另一个负责实现该接口。Person定义如下:

2015-10-04 18:55:44 453

原创 条款14:在资源管理中心小心copy行为之重难点

不仅仅动态分配的内存是资源,像文件描述器,互斥锁,数据库连接,以及网络sockets等也是资源,如果不及时关闭,也会造成资源浪费。重点1:建立自己的资源管理类如果是heap-based资源,则可以用auto_ptr或shared_ptr管理资源。然而并非所有资源都是heap-based,这样,就需要建立自己的资源管理类。以互斥锁为例,为确保不会忘记将一个被锁住的mutex解锁,我们希望

2015-10-04 13:49:26 584

原创 条款7中提及工厂method

一、概述 工厂方法是创建型模式,允许在不指定需要创建对象类型的情况下创建出对象。本质上来说,工厂方法就是一个通用的构造函数。C++中的构造函数有以下几种限制:1无返回值(No return result)。在构造函数中不能返回一个值。这就意味着:例如当构造失败时不能返回一个NULL作为初始化失败的信号。2 命名有约束(Constrained naming)。构造函数还是

2015-10-04 11:31:26 272

原创 条款25:全特化和偏特化

条款25:考虑写出一个不抛异常的swap函数,中提到了模板的全特化,很遗憾,我又没有听过。全特化:就是全部特化,即针对所有的模板参数进行特化。偏特化:就是部分特化,即针对部分模板参数进行特化。#include using namespace std;template T mymax(const T t1, const T t2){ return t1 < t2 ? t2 :

2015-10-03 16:06:50 373

原创 条款21:static对象引起的多线程安全性

看到条款21:必须返回对象时,别妄想返回其reference时,看到一句话“就像所有用上static对象的设计一样,这一个也立刻造成我们对多线程安全性的疑虑。”虽然多线程有一点了解,但多线程安全性居然还没听过(囧)。#include #include long global1 = 0;volatile long global2 = 0;class MyClass{public:

2015-10-03 14:34:26 720

原创 条款20:宁以pass-by-reference-to-const替换pass-by-value

前面的道理我都懂,什么pass-by-value会调用赋值构造函数和析构函数,成本高,而pass-by-reference-to-const可以回避构造和析构。后面提到by-reference方式传递参数也可以避免sliding(对象切割)问题。 ~~~等等,对象切割是什么鬼,effective C++果然有100种方式让我看不下去。1.对象切割首先我自己举个简单的例子,说明:

2015-10-03 14:05:57 350

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除