lzhenf

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  C++

摘要:STL源码剖析第一章主要介绍的STL的历史由来和重要组成部分。STL有以下六大组件:1.容器(containers):各种数据结构,如vector,list,deque,set,map用来存储数据,从实现的角度来看,容器是一个class template,就体积而言,这一部分很像冰山在海面下的比率。2.算法(algorithm):各种算法如sort,search,copy,erase....等等, 从实现的角度来说,算法是一个function template。3.迭代器(iterator):扮演容器和算法之间的粘合剂,所谓的泛型指针,共有5种类型,以及他们的衍生变化,从实现的角度来看,迭代器 阅读全文
posted @ 2013-08-18 22:17 lzhenf 阅读(336) 评论(0) 推荐(0)

摘要:#include <stdio.h>int arr[]= {3,8,11,92,34,12,7};int partition(int l , int r ){ int x = arr[r]; int temp; int i = l -1 ; for ( int j = l ; j < r ; j++) if ( arr[j] < x) { i++; temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; ... 阅读全文
posted @ 2012-04-04 04:04 lzhenf 阅读(247) 评论(0) 推荐(0)

摘要:#include <stdio.h>#include <stdio.h>#include <iostream>using namespace std;class Base{ public: virtual void f(){cout <<"Base:f"<<endl;} virtual void g(){cout<<"Base:g"<<endl;} virtual void h(){cout<<"Base :h" <<endl; 阅读全文
posted @ 2012-04-03 23:56 lzhenf 阅读(361) 评论(1) 推荐(0)

摘要:int binarysort(int begin , int end , int target){ if ( begin >end ) return -1 ; int middle = (begin + end ) >>1; if ( arr[middle ] == target ) return middle; else if ( target > arr[middle]) binarysort( middle +1 , end, target); else ... 阅读全文
posted @ 2012-03-28 15:39 lzhenf 阅读(163) 评论(0) 推荐(0)

摘要:/*********************** * author :lzhenf * it's a program with args for mutithread in linux OS * date:2012.3.27 * ***********************/#include <stdio.h>#include <pthread.h>void* mythread(void* args){ char *str1; str1 = (char *)args; sleep(5); printf("the thread id is %u&quo 阅读全文
posted @ 2012-03-27 15:47 lzhenf 阅读(199) 评论(0) 推荐(0)

摘要:布局new和普通New不同,相当于建立一个小堆空间 。#include <iostream>#include <string>#include <new>using namespace std;const int BUF = 512;class testing{private : string word; int len;public: testing(const string & s = "tesing",int n = 0 ) { word = s; len = n; cout <<word <<&qu 阅读全文
posted @ 2012-03-23 22:15 lzhenf 阅读(282) 评论(0) 推荐(0)

摘要:用bitmap方法,内存只需要 512M左右#include <stdio.h>#include <memory.h>#define BYTESIZE 8long long bufferlen =500000000;char *pBuffer = new char[bufferlen]; void setbit(char * p , int posi){ for ( int i = 0 ; i < posi / BYTESIZE ; i++) { p++; } *p = *p | (0x01 << (posi % BYTESIZE)) ;}int ma 阅读全文
posted @ 2012-03-21 23:54 lzhenf 阅读(625) 评论(0) 推荐(1)

摘要:某天有1千万条查询,大部分为重复的,可能只有300万条查询,每条查询的长度为1-255字节,请设计算法查找出最热门的10条查询哈希 + 最小堆 时间复杂度为O(nlgk) n为数据量 , k为查询长度,这里为10;#include <stdio.h>#include <cstring>#include <algorithm>using namespace std;#define HASHLEN 2807303#define CHARLEN 30typedef struct node_no_space* ptr_no_space;typedef struct 阅读全文
posted @ 2012-03-21 21:09 lzhenf 阅读(2039) 评论(0) 推荐(0)

摘要:#include <stdio.h>typedef struct node{ int val; node* next;};node* reverse(node* list , node* &head){ if ( !list || !list->next ) { head->next = NULL; head = list; return list; } else { node* temp = reverse( list->next , head); temp->next = list; return list; }}node* nonreverse 阅读全文
posted @ 2012-03-19 23:22 lzhenf 阅读(3699) 评论(0) 推荐(0)

摘要:int checkCPU( ){ { union w { int a; char b; } c; c.a = 1; return(c.b ==1);} } 阅读全文
posted @ 2012-03-19 22:05 lzhenf 阅读(268) 评论(0) 推荐(0)

摘要:【转自:http://www.ibm.com/developerworks/cn/linux/sdk/python/python-5/index.html#N1004E】我们谈到“文本处理”时,我们通常是指处理的内容。Python 将文本文件的内容读入可以操作的字符串变量非常容易。文件对象提供了三个“读”方法: .read()、.readline() 和 .readlines()。每种方法可以接受一个变量以限制每次读取的数据量,但它们通常不使用变量。 .read() 每次读取整个文件,它通常用于将文件内容放到一个字符串变量中。然而 .read() 生成文件内容最直接的字符串表示,但对于连续的面 阅读全文
posted @ 2012-03-06 15:34 lzhenf 阅读(721) 评论(0) 推荐(0)

摘要:第五章 代理类 :为了实现容器或数组的多态性。 1 #include <iostream> 2 3 using namespace std; 4 5 class Vehicle 6 { 7 public: 8 virtual void start() const = 0 ; 9 virtual Vehicle* copy() const = 0 ;10 virtual ~Vehicle() {};11 };12 13 14 class AutoVehicle : public Vehicle 15 {16 public:17 void start() con... 阅读全文
posted @ 2011-12-28 00:36 lzhenf 阅读(262) 评论(0) 推荐(0)