随笔分类 -  C++ 语言学习

摘要:最近看了侯捷翻译的STL源码剖析,感觉有些启发。迭代器:Allocator 空间配置器,全域函数 construct(), destroy()iterator 是个智能指针,可以从原生指标提取出需要的类别。这样,容器需要实现自己迭代器。容器RB tree的在STL的使用还是很广泛的,不仅是map,set也是用的RB tree根据Vector的特点,迭代器就是使用的原生指针,作为迭代器的指针使用List的迭代器不是原生指针,因为++实际上不是地址的++,而是取得next指针。list遍历的代码,注意拼写 list<int>::iterator ite; for(ite = ilist 阅读全文

posted @ 2011-11-25 15:42 Teddy Yan 阅读(338) 评论(0) 推荐(0) |

摘要:其实题目很简单,就是计算一个整数数组中,连续的最大子数组。一开始想到肯定是个O(n*n)的算法:maxSectionGood后来使用递归O(n*log(n)):maxSectionExcellent最经典的是最后一个算法,提升到了O(n):maxSectionPrefectGoogle 笔试题:input: an array of int which represent a binary number the bit is 1output: the count of 1 triple of the numberinput: an array of intoutput: the max sum 阅读全文

posted @ 2010-12-16 10:36 Teddy Yan 阅读(238) 评论(0) 推荐(0) |

摘要:1. Layout Cost for Adding Encapsulationinheritance don't have cost. But virtual function and virtual base class will add extra cost.2. C++ Object ModelHow Compiler implement the OO:A Simple Object ModelA Table-driven Object ModelTwo conceptions: virtual table vtbl;vptrHow the Object Model Effect 阅读全文

posted @ 2007-02-19 22:08 Teddy Yan 阅读(142) 评论(0) 推荐(0) |

摘要:1.&语法糖2.Make 编译控制 //{L} Global2 带有Global2名字的文件要被连接进来(很像xdoclet)3.变量的定义:extern, static(两种含义:作用域内不变,指定作用域) and automatic4.Link: internal linkage 和 external linkage 5.C++ 显示转换 l=static_cast<long>(i); const int i=0;const_cast<int *>(&i);X x;int* xp = reinterpret_cast<int *>(&am 阅读全文

posted @ 2006-12-08 14:49 Teddy Yan 阅读(112) 评论(0) 推荐(0) |

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3