上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 34 下一页
摘要: 一.list的成员函数Iterators:list.begin()回传指向第一个元素的 Iterator。list.end()回传指向最末元素的下一个位置的 Iterator。list.rbegin()回传指向最末个元素的反向 Iterator。list.rend()回传指向第一个元素的前一个位置的反向 Iterator。Capacity/Size:list.empty()若list内部为空,则回传true值。list.size()回传list内实际的元素个数。lsit.resize()重新分派list的长度。Element Accesslist.front()存取第一个元素。list.bac 阅读全文
posted @ 2014-01-09 16:21 七年之后 阅读(387) 评论(0) 推荐(0) 编辑
摘要: 与普通数组array不同,vector是动态空间,它支持随机存取,在集合尾端增删元素很快,但是在集合中间增删元素比较费时。随着元素的加入,它会自行扩充空间来容纳新元素,这些特性都是vector实现技术的关键所在。一.vector成员函数: 首先了解vector的各个成员函数的作用:1.访问元素的方法vec[i]- 访问索引值为 i 的元素引用。 vec.at(i)- 访问索引值为 i 的元素的引用,以 at() 访问会做数组边界检查,如果访问越界将会抛出异常。vec.front()- 回传 vector 第一个元素的引用。vec.back()- 回传 vector 最尾元素的引用。2.新增或. 阅读全文
posted @ 2014-01-09 00:15 七年之后 阅读(406) 评论(0) 推荐(0) 编辑
摘要: 考虑到过多“小型区块”可能造成的内存碎片问题,SGI设计了双层级配置器: 第一级配置器直接调用malloc()和free(); 第二级配置器分两种情况:当配置区块大于128字节时,调用第一级配置器;当配置区块小于128字节时,采用内存池管理。一.第一级配置器1.__malloc_alloc_tempalte源码template class __malloc_alloc_template {private: //以下函数用来处理内存不足的情况 static void *oom_malloc(size_t); static void *oom_realloc(void *, size_... 阅读全文
posted @ 2014-01-08 15:28 七年之后 阅读(423) 评论(0) 推荐(0) 编辑
摘要: Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For example, givens="leetcode",dict=["leet", "code"].Return true because"leetcode"can be segmented as"leet code&quo 阅读全文
posted @ 2014-01-07 15:14 七年之后 阅读(207) 评论(0) 推荐(0) 编辑
摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the value if the key is not 阅读全文
posted @ 2014-01-06 22:03 七年之后 阅读(193) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list in O(n log n) time using constant space complexity.思路:分治+递归。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {private: int getlen(ListNode *head) { Lis... 阅读全文
posted @ 2014-01-06 16:35 七年之后 阅读(240) 评论(0) 推荐(0) 编辑
摘要: 一.I/O复用 在《TCP套接字编程》的同步聊天程序中,我们看到TCP客户同时处理两个输入:标准输入和TCP套接字。考虑在客户阻塞于标准输入fgets调用时,服务器进程被杀死,服务器TCP虽然会给客户TCP发送一个FIN,但是客户客户进程正阻塞于标准输入读入过程,它将看不到这个EOF,直到从... 阅读全文
posted @ 2014-01-02 16:27 七年之后 阅读(310) 评论(0) 推荐(0) 编辑
摘要: Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.思考:考虑以下几种情况:1.points中0、1、2个点;2.points含相同点如{[0,0],[0,0]},{[1,1],[1,1],[2,2],[2,2]}};3.斜率为无穷。/** * Definition for a point. * struct Point { * int x; * int y; * Point() : x(0), y(0) {} * Poi... 阅读全文
posted @ 2013-12-29 19:40 七年之后 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 一.套接字(socket)函数 图1给出了在一个TCP客户与服务器通信的流程。服务器首先启动,稍后某个客户启动,它试图连接到服务器。假设客户给服务器发送一个请求,服务器处理该请求,并且给客户发回一个相应。这个过程一直持续下去,知道客户关闭连接的客户端,从而给服务器发送一个EOF(文件结束)通知为止... 阅读全文
posted @ 2013-12-27 17:49 七年之后 阅读(3144) 评论(0) 推荐(0) 编辑
摘要: 通过配置nginx.conf文件来实现对Nginx状态信息的监控。1.配置nginx.confvim /usr/local/nginx/conf/nginx.conf再server块配置项中添加状态监控代码:location /nginx-status { stub_status on; #Nginx状态监控配置 access_log off;}2.编译模块上述代码中的stub_status模块是用来查看Nginx的状态信息,但是它默认是不会编译进Nginx的,所以要在编译安装Nginx时指定:./configure --prefix=/usr/local/nginx --... 阅读全文
posted @ 2013-12-22 16:47 七年之后 阅读(319) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 34 下一页