上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 48 下一页
摘要: 算法描述:功能:将一段数据转换为max-heap.(父节点不小于子节点的完全二叉树。)基本步骤:从某一子树开始进行下溯操作。开始的子树:Distance parent = (len - 2)/2; 最后的叶节点不必执行下溯。该子树执行完下溯后parent—;下溯:将空洞节点(这里是parent,即开始执行下溯的节点)与较大子节点对调,并持续下放,直到叶节点为止。SGI STL实现:// 以下這組 make_heap() 不允許指定「大小比較標準」。template <class RandomAccessIterator, class T, class Distance>void _ 阅读全文
posted @ 2013-01-05 17:34 helloweworld 阅读(651) 评论(0) 推荐(0) 编辑
摘要: pop_heap和sort_heap操作的对象是max-heap,即父节点比子节点大的heap结构。 push_heap是将使插入新元素后仍满足max-heap结构(原来也是max-heap结构)。 make_heap是讲一段数据转化为max-heap. 因为每次pop_heap可获得heap中键值最大的元素,所以可持续对整个heap做pop_heap操作,每次将操作范围从后向前缩减一个元素,便... 阅读全文
posted @ 2013-01-05 16:57 helloweworld 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 算法描述 置根节点于容器尾部,并调整heap结构使其满足max-heap. 算法的核心是根节点为空洞后heap结构的调整,而不是取最大值(最大值就是根节点)! 根节点为空洞后,为了满足max-heap结构,要割舍最下层最右边的叶节点,重新安插它的位置,即调整heap结构。 注:根节点即最大元素只是被置放于底部容器的最尾端,尚未被取走,可通过back()操作取其值,可通过pop_back()... 阅读全文
posted @ 2013-01-05 16:44 helloweworld 阅读(935) 评论(0) 推荐(0) 编辑
摘要: 算法描述 完全二叉树,父节点值比子节点大。(不保证左节点值大于右节点值。) 新元素插入时要满足的条件 为了满足完全二叉树的条件,新加入的元素一定要放在最下一层作为叶节点,并填补在由左至右的第一个空格,也就是把新元素插入在底层vector的end()处。 用到的技巧 这里有一个小技巧,如果用array存储所有节点,并且将array的#0位置的元素保留(即下标从1开始),那么当完全二叉树的某个节点... 阅读全文
posted @ 2013-01-05 11:50 helloweworld 阅读(486) 评论(0) 推荐(0) 编辑
摘要: void transfer(iterator position, iterator first, iterator last) { if (position != last) { (*(link_type((*last.node).prev))).next = position.node; (*(link_type((*first.node).prev))).next = last.node; (*(link_type((*position.node).prev))).next = first.node; link_type tmp = lin... 阅读全文
posted @ 2013-01-04 15:44 helloweworld 阅读(231) 评论(0) 推荐(0) 编辑
摘要: iterator erase(iterator position) { link_type next_node = link_type(position.node->next); link_type prev_node = link_type(position.node->prev); prev_node->next = next_node; next_node->prev = prev_node; destroy_node(position.node); return iterator(next_node);}iterator erase(iterator... 阅读全文
posted @ 2013-01-04 15:33 helloweworld 阅读(372) 评论(0) 推荐(0) 编辑
摘要: /*stl_list.h文件中*/iterator insert(iterator position, const T& x) { link_type tmp = create_node(x); tmp->next = position.node; tmp->prev = position.node->prev; (link_type(position.node->prev))->next = tmp; position.node->prev = tmp; return tmp;}void push_front(const T& x) { i 阅读全文
posted @ 2013-01-04 15:30 helloweworld 阅读(453) 评论(0) 推荐(0) 编辑
摘要: 一、 http://www.sgi.com/tech/stl/download.html 或 http://download.csdn.net/download/ljljlj/3658798 (侯捷配套源码) 已下载在G盘。 二、 linux下 /usr/include/c++/4.3 三、 已安装c++集成环境就有C++ STL源码。 阅读全文
posted @ 2013-01-03 16:00 helloweworld 阅读(2175) 评论(0) 推荐(0) 编辑
摘要: 什么是静态链接,动态链接 如果函数库的一份拷贝是可执行文件的物理组成部分,那么我们称之为静态链接。 如果可执行文件只是包含了文件名,让载入器在运行时能够寻找程序所需的函数库,那么称为动态链接。 即根据函数库是不是可执行文件的组成部分区分静态链接和动态链接。 动态链接的优点 1、可执行文件的体积小。 2、虽然运行速度稍慢,但是能更加有效的利用磁盘空间,因为函数库只有在需要时才被映射到进程中。 3、操作系统内核保证映射到内存中的函数库能被使用它们的所有进程共享,从而提高系统整体性能,如果是静态链接,则每个文件都会拥有一份单独的拷贝,无疑浪费资源。 即动态链接的函数库是共享的。 阅读全文
posted @ 2013-01-02 14:33 helloweworld 阅读(186) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std;class A {public: A() { cout using namespace std;class A {public: A() { cout << "call A()" << endl; } virtual ~A() { cout << "call ~A()"; }};class B:public A { char *buf;public: B() { buf = new char[100]; cout << "call B()& 阅读全文
posted @ 2012-12-31 22:28 helloweworld 阅读(143) 评论(0) 推荐(0) 编辑
上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 48 下一页