
C++
SUN_DRAGON
这个作者很懒,什么都没留下…
展开
-
C++文件操作
C++ 通过以下几个类支持文件的输入输出:ofstream: 写操作(输出)的文件类 (由ostream引申而来) ifstream: 读操作(输入)的文件类(由istream引申而来) fstream: 可同时读写操作的文件类 (由iostream引申而来) 打转载 2011-08-30 14:57:02 · 626 阅读 · 0 评论 -
Path Sum
Path SumOct 14 '124097 / 9547Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Giv原创 2013-07-18 11:57:55 · 2225 阅读 · 0 评论 -
Path Sum II
Path Sum IIOct 14 '123844 / 10801Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22,原创 2013-07-18 14:03:53 · 1351 阅读 · 0 评论 -
Minimum Depth of Binary Tree
Minimum Depth of Binary TreeOct 10 '124568 / 11410Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the near原创 2013-07-18 14:22:13 · 1679 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search TreeOct 3 '123397 / 9589Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 刚开始想用课本上的构造平衡二叉树的方法原创 2013-07-22 16:27:45 · 666 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST. /** * Definition for binary tree * struct TreeNode原创 2013-07-22 16:37:57 · 844 阅读 · 0 评论 -
Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal IIGiven a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example原创 2013-07-22 16:58:12 · 1383 阅读 · 0 评论 -
Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2013-07-22 17:15:42 · 822 阅读 · 0 评论 -
hash_map 使用
今天在使用STL中的hash_map模板遇到使用PTCHAR作为Key时无法对字符串进行正确比较的问题,在网上查找相应的文章可惜没有找到,但找到了http://www.stlchina.org/twiki/bin/view.pl/Main/STLDetailHashMap和http://www.cppblog.com/guojingjia2006/archive/2008/01/12/41037.转载 2013-08-08 21:53:53 · 921 阅读 · 0 评论 -
Unique Binary Search Trees
Unique Binary Search TreesAug 27 '123164 / 5973Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 uniqu原创 2013-08-09 17:08:55 · 854 阅读 · 0 评论 -
static_cast、dynamic_cast、reinterpret_cast、和const_cast
关于强制类型转换的问题,很多书都讨论过,写的最详细的是C++ 之父的《C++ 的设计和演化》。最好的解决方法就是不要使用C风格的强制类型转换,而是使用标准C++的类型转换符:static_cast, dynamic_cast。标准C++中有四个类型转换符:static_cast、dynamic_cast、reinterpret_cast、和const_cast。下面对它们一一进行介绍。stat转载 2013-08-16 14:49:05 · 642 阅读 · 0 评论 -
二维指针
void func1(int **p){}void func2(int *p[10]){}void func3(int p[10][10]){}void func1(int (*p)[10]){}void func1(int *p[10]){//重载失败,与第一个参数相同}int main(){ int a[10][10]; func1(a);//不能从(*a)[10]转换为**p原创 2013-09-02 17:32:05 · 604 阅读 · 0 评论 -
DLL中传递STL参数
DLL中传递STL参数,vector对象作为dll参数传递等问题(转) STL跨平台调用会出现很多异常,你可以试试.STL使用模板生成,当我们使用模板的时候,每一个EXE,和DLL都在编译器产生了自己的代码,导致模板所使用的静态成员不同步,所以出现数据传递的各种问题,下面是详细解释。 原因分析:一句话-----如果任何STL类使用了静态变量(无论是直接还是间转载 2013-09-04 17:05:03 · 1181 阅读 · 0 评论 -
Flatten Binary Tree to Linked List
Flatten Binary Tree to Linked List Oct 14 '124412 / 13068Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \原创 2013-07-18 11:45:43 · 3142 阅读 · 0 评论 -
Distinct Subsequences
Distinct SubsequencesOct 19 '123689 / 10619Given a string S and a string T, count the number of distinct subsequences ofT in S.A subsequence of a string is a new string which is formed from th原创 2013-07-18 09:49:05 · 1482 阅读 · 0 评论 -
C/C++中的静态变量和函数
先说说C中的静态变量和静态函数。(1)C中的静态变量是处于全局存储区,区别于自动变量的存储于栈中。两者的关键区别是其作用域的区别。自动变量的作用域处于其所在的函数或语句块中;而静态变量的作用域起始于其定义处,终止于程序结束处。(2)C中的静态函数主要是限制函数的名字以及可访问域于文件中,表示此函数仅供此文件所用,不允许在其他文件中调用的。有关静态函数的使用可以考虑几点:一是静态函数的名字仅可见于其转载 2012-03-24 12:58:17 · 669 阅读 · 0 评论 -
得到自己的帧率
#define FRAME_RATE 60int g_fps = 0; // FPS帧率值char g_fpsStr[16] = {0}; // 存放帧率值int g_fpsInt = 0;float g_time = 0.0f; // 系统运行时间float g_lastTime = 0.0f; // 持续的时间int freq原创 2012-03-29 15:16:29 · 898 阅读 · 0 评论 -
opengl 点精灵的使用
1、导入glext动态链接库中的函数#include PFNGLPOINTPARAMETERFARBPROC glPointParameterfARB = NULL;PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB = NULL;char* ext = (char*) glGetString(GL_EXTENSIONS); if(原创 2012-03-29 22:11:05 · 3071 阅读 · 0 评论 -
动态链接库的创建1
1、动态链接库分为:Non-MFC DLL、MFC Regular DLL(MFC规则DLL)、MFC Extension DLL(MFC扩展DLL)Non-MFC DLL文件隐式调用:2、创建工程win32 project,并选择 DLL 链接库。3、在cpp文件中添加如下代码:#include "stdafx.h"#ifndef DYNAMIC_CPP#define转载 2012-03-14 17:09:02 · 661 阅读 · 0 评论 -
动态链接库与静态链接库
动态链接库静态链接库生成的文件不同*.dll *.lib*.lib文件功能lib是编译链接时需要,dll是运行时需要的。如果要完成代码编译,有lib就行;如果使动态链接的程序运行起来,有dll就够了。lib文件必须在编译器就连接在应用程序;dll在运行期才会调用。如果只有lib文件,则这个礼拜是静态编译出来的,索引和实现在其中。原创 2012-03-14 14:32:44 · 834 阅读 · 0 评论 -
拷贝构造函数和赋值函数
赋值函数每个类只有一个赋值函数.由于并非所有的对象都会使用拷贝构造函数和赋值函数,程序员可能对这两个函数有些轻视。请先记住以下的警告,在阅读正文时就会多心:1.如果不主动编写拷贝构造函数和赋值函数,编译器将以“位拷贝”的方式自动生成缺省的函数。倘若类中含有指针变量,那么这两个缺省的函数就隐含了错误。以类String的两个对象a,b为例,假设a.m_data的内容为“hello”转载 2013-03-02 14:58:18 · 508 阅读 · 0 评论 -
make_heap, push_heap, pop_heap, 的使用
stl make_heap使用发表于 2012 年 02 月 04 日 由 dllgwgy摘要:好久没有写blog,翻译一篇cplusplus上的make heap文档,凑凑数吧。在工程项目中有不少需求是多次求最大数或者最小数,堆是好的选择之一。如果我比较懒,又比较严谨的话,项目也允许使用stl的话,我会采用STL的make_heap, push_heap, pop_h转载 2013-03-20 15:12:21 · 3630 阅读 · 0 评论 -
longest consecutive elements sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3,原创 2013-03-21 12:10:20 · 993 阅读 · 0 评论 -
c++ 深拷贝浅拷贝
C++的深拷贝与浅拷贝本文的所有内容均来自http://www.cnblogs.com/BlueTzar/articles/1223313.html,感谢此作者:) 对于普通类型的对象来说,它们之间的复制是很简单的,例如:int a=88;int b=a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量。转载 2013-03-25 09:25:33 · 681 阅读 · 0 评论 -
C++ 位对齐操作
看到一个宏 : #define PAD_ALIGN(x, mask) ((x + mask)&~mask) 首先要了解对齐操作,就是指位数不够y的倍数时最后用一个y的补齐。例如:12不是8的倍数,如果对8对齐,则位数应该为16。 应用的话,在图像的存储上有应用,例如24位图在存储时行的位数应为32的倍数。再看这个宏,就明朗了。如若x的后mask(00011111,1的个数)位有1存在(原创 2013-07-08 09:59:52 · 1967 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node II
Populating Next Right Pointers in Each Node IIOct 28 '123191 / 7859Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would yo原创 2013-07-17 17:28:23 · 1506 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If t原创 2013-07-17 15:59:52 · 703 阅读 · 0 评论 -
C++封装python接口(libboost-python)
摘要在Python技术文档中可以找到关于Python与C++之间相互调用的部分。分别叫做extending和Embedding。可以参考技术文档Extending and Embedding the Python Interpreter。于此同时,还提供了 Python/C API接口Python/C API Reference Manual。虽然对于简单的调用使用起来很方便,但对于复杂的结构、封装原创 2016-07-13 17:34:56 · 5473 阅读 · 0 评论