- 博客(242)
- 资源 (23)
- 收藏
- 关注
原创 我的.vimrc文件
set nocompatibleset autoindentset smartindentset showmatchset rulerset incsearchset mouse=nset tabstop=4set shiftwidth=4set softtabstop=4set cindentsyntax enableset numberset confirmset
2014-07-28 19:41:56
909
原创 第九章 select模式下的非阻塞连接
#include #include #include #include #include #include #include #include #include #include #include #include #include #define BUFFER_SIZE 1023int setnonblocking( int fd ){ int old_
2014-07-13 17:11:52
1032
原创 第九章 select用法初试
#include #include #include #include #include #include #include #include #include #include #include int main( int argc, char* argv[] ){ if( argc <= 2 ) { printf( "usage: %s ip_address
2014-07-13 16:46:04
755
原创 华为上机 公共字串计算
我用这种方法,提交了好几次,#include#include#include#includeusing namespace std;int getCommonStrLength(char *pFirstStr,char *pSecondStr){ if(strlen(pFirstStr)==0||strlen(pSecondStr)==0)
2014-07-12 16:01:35
1031
4
原创 leetcode 11 Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?
2014-07-10 16:50:26
701
原创 leetcode 10 Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?
2014-07-10 16:39:47
695
原创 leetcode 17 Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on
2014-07-10 15:42:07
683
原创 leetcode 15 Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u
2014-07-10 15:02:32
782
原创 leetcode 66 Plus One
#include#include#includeusing namespace std;vector plusOne(vector &digits){ int len=digits.size(); vector res(digits); int carrybit=1,i; for(i=len-1;i>=0;i--)
2014-07-09 21:15:28
656
原创 leetcode 74 Subsets
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exa
2014-07-09 15:34:32
721
原创 leetcode 75 Combinations
#include#include#includeusing namespace std;void com(int depth,int n,int k,vector v,vector > &res){ if(v.size()==k) { res.push_back(v); return ;
2014-07-09 15:06:49
784
原创 leetcode 46 Permutations
#include#include#includeusing namespace std;void perm(int start,int end,vector in,vector > &res){ if(start==end) { res.push_back(in); return ;
2014-07-09 11:26:41
693
原创 leetcode 149 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo
2014-07-07 22:01:15
642
原创 leetcode 127 Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word m
2014-07-07 16:20:16
1086
原创 leetcode 150 Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
2014-07-07 11:06:19
862
原创 leetcode 151 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe
2014-07-06 21:06:24
853
转载 ubuntu 安装 openssh-server
一直想不下linux技术,一直没有时间弄,最近由于工作上的需要,需要熟悉linux系统,借此机会好好学习一下首是是最其本的,安装openssh-server,方便远程访问,使用Putty可以访问ubuntu PuTTY 是一套免费的 SSH / Telnet 程序,它可以连接上支持 SSH Telnet 联机的站台,并且可自动取得对方的系统指纹码(Fingerprint)。建
2014-07-03 13:56:25
833
转载 Ubuntu下搭建FTP服务器
服务器系统是Ubuntu 12.04 LTS,FTP软件当然是选择大名鼎鼎的vsftpd(very secure FTP daemon), 用系统自带的FTP还好Ubuntu装vsftpd还是很简单,一句命令就行:sudo apt-get install vsftpd命令执行过程中,安装程序会给本地创建一个名为“ftp”的用户组,命令执行完之后会自动启动FTP服务。可以使用
2014-07-03 13:55:45
750
原创 C++ STL学习之九:关联式容器map深入学习
MAP容器 1)概念:map 是一个容器,它用于储存数据并且能从一个数据集合中取出数据。它的数据组成包含两项,一个是它的数据值,一个是用于排序的关键字。其中关键字是惟一的,它用于将数据自动排序。而每个元素的数据值与关键字无关,可以直接改变。 【重点】内部结构采用RB_TREE(红黑树)。查找复杂度:O(log2N)
2014-07-02 17:26:39
739
原创 C++ STL学习之八:关联式容器set深入学习
set和map的最大不同就是set是单值,而map是键值对, 当然set也可以理解成键值对相等的特殊键值对。这样讲的话,我们大概就知道了,它们的底层实现就是一个东西。那么multiset和set有什么区别呢?主要值能不能重复的问题,如果可以保存多个相同值的话就使用multiset否则就使用set。因为插入的时候,它们分别调用的是insert和unique_insert;同理,map和multima
2014-07-02 17:02:39
786
原创 C++ STL学习之七:配接器priority_queue深入学习
priority_queue是一个带有权值观念的队列,因此取出元素的时候只能取出权值最大的元素。 priority_queue完全以底层容器为根据(缺省为vector),加上heap处理规则实现。
2014-07-02 16:15:20
722
原创 C++ STL学习之六:配接器queue深入学习
一,概述 先进先出的数据结构,底端加入元素,顶端移除元素,类似stack同样不能有遍历行为,没有迭代器。也是以既有容器为底端容器被归类为陪接器(container adapter),默认底端容器为deque。二,使用 #include using namespace std;三,方法queue:
2014-07-02 15:38:42
684
原创 C++ STL学习之五:配接器stack深入学习
stack是一种先进先出的数据结构。只能在栈顶操作。它以底层容器完成所有的操作,因此是一个adapter(配接器)。
2014-07-02 15:28:50
623
原创 C++ STL学习之四:序列式容器list深入学习
特点:1)环状双向链表,对于任何位置的元素插入或删除是常数时间2)插入和接合不会使原有list迭代器失效list迭代器:不能以普通指针为迭代器,使用bidirectional iterator插入操作:本质是插入在…之前,新节点位于标示出插入点所指节点的前方,插入前的所有迭代器在插入后有效
2014-07-02 14:48:12
833
原创 C++ STL学习之一:STL概况
0. STL综述STL(Standard Template Library)C++模板库,该书剖析的是SGI版本的STL,是GNU C++的标准库。STL的价值:1.带给我们一套极具实用价值的零部件,一集一个整合的组织。2.STL带给我们一个高层次的,已泛型思维为基础的,系统化的,条理分明的“软件组件分类学”。STL六大组件:1.容器(vector, list, deque
2014-07-02 10:51:26
842
原创 C++ STL学习之二:序列式容器vector深入学习
vector的空间可扩充,支持随机存取访问,是一段连续线性的空间。所以它是动态空间,与之对比的array是静态的空间,不可扩充。简单来说,vector是数组的增强版。
2014-07-02 10:39:42
739
原创 C++ STL学习之三:序列式容器deque深入学习
deque是双端队列,它的空间构造并非一个vector式的长数组,而是“分段存储,整体维护”的方式;STL允许在deque中任意位置操作元素(删除添加)(这超出了deque的概念,最原始的deque将元素操作限定在队列两端),允许遍历,允许随机访问(这是假象);我们将看到,deque将是STL中stack和queue的幕后功臣,对deque做适当的修正,便可以实现stack和queue。
2014-07-02 10:12:31
810
转载 Careercup | Chapter 5
5.1 You are given two 32-bit numbers, N andM, and two bit positions, i and j. Write a method to insert M into Nsuch that M starts at bit j and ends at bit i. You can assume that the bits j through i
2014-06-30 18:04:14
690
转载 matlab中记录程序运行时间
使用Matlab运行程序的时候,我们经常需要知道或比较不同程序的具体运行时间,其程序代码如下:st=cputime; % 程序开始运行时的cpu时间% 程序开始……% 程序结束et=cputime-st % 计算程序运行所用的时间
2014-06-26 10:26:48
26611
原创 Linux high performance:http请求的读取和分析
#include #include #include #include #include #include #include #include #include #include #define BUFFER_SIZE 4096enum CHECK_STATE { CHECK_STATE_REQUESTLINE = 0, CHECK_STATE_HEADER, CHECK_
2014-06-25 15:33:01
702
原创 Libevent群:很值得体会的多线程编程
/* This exmple program provides a trivial server program that listens for TCP connections on port 9995. When they arrive, it writes a short message to each client connection, and closes each co
2014-06-25 11:29:20
2267
原创 Libevent群:很值得体会的bufferevent+evconnlistener
//说明,为了使我们的代码兼容win32网络API,我们使用evutil_socket_t代替int,使用evutil_make_socket_nonblocking代替fcntl/* For sockaddr_in */#include /* For socket functions */#include /* For fcntl */#include #in
2014-06-25 10:45:17
819
转载 libevent源码浅析: http库
from 转自:http://godorz.info/author/godorz/page/3/libevent自带了一个http库,用它可以很简单的实现一个http服务器,本文非常简单地分析之.evhttpevhttp库有几个主要的结构体,它们之间的联系非常龌龊:其中,结构体event, min_heap, evsignal_info, e
2014-06-22 20:34:20
1367
转载 libevent多线程使用事项
在linux平台上使用c开发网络程序的同志们一般情况下都对鼎鼎大名的libevent非常的熟悉了。但是一些新进入此领域的new new people们对此都是一头雾水。原本的迷茫再加上开源软件一贯的“帮助文件”缺失作风,让我们这些新手们显的非常的无助。幸好有一些热心的朋友们帮忙,才化险为夷啊! 前几天一直在开发一个locker server,虽然公司现有的locker server能
2014-06-22 20:27:35
1107
转载 libevent带负载均衡的多线程使用示例
分类: LINUX功能:主线程根据负载工作线程负载均衡算法,每隔一秒钟向特定的工作线程发送一条字符串信息,工作线程简单的把字符串信息打开出来。Makefileeventtest : eventtest.cgcc -Wall -g -levent -lpthread -o eventtest eventtest.c.PHONY : cleancle
2014-06-22 19:55:48
932
转载 用libevent多线程方式实现echo server
功能:主线程同时监听定时器事件和IO事件,工作线程简单的监听IO事件。主线程每隔一秒种向工作线程发送一条字符串信息工作线程显示该信息并回显给主线程该示例演示了主线程如何同时监听多个事件。Makefileeventtest : eventtest.cgcc -Wall -g -levent -lpthread -o eventtest ev
2014-06-22 19:36:35
871
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人