
c++
我爱吃火锅
游戏开发者
展开
-
typedef用法总结
typedef可以用来定义类型的同义词:typedef double wages;wages huors;等价于:double huors; typedef char line[81];line text;等价于:char text[81]; typedef string *zhizhen;zhizhen p;等价于:string *p; ty原创 2013-01-27 16:41:20 · 327 阅读 · 0 评论 -
leetcode之Best Time to Buy and Sell Stock
题目意思:Best Time to Buy and Sell Stock原创 2014-04-24 19:32:59 · 557 阅读 · 0 评论 -
leetcode之Candy
题目大意:There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at原创 2014-04-11 20:07:37 · 1243 阅读 · 0 评论 -
leetcode之Triangle
题目大意:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4原创 2014-04-27 20:28:19 · 5770 阅读 · 3 评论 -
leetcode之Best Time to Buy and Sell StockII
题目大意:Say you have an array for which the ith element is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the原创 2014-04-26 22:08:57 · 680 阅读 · 0 评论 -
leetcode之Best Time to Buy and Sell Stock III
题目大意:Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:Yo原创 2014-04-27 20:11:18 · 698 阅读 · 0 评论 -
分清operator new和new operator
在C++中new operator与operator new非一回事也,new operator(即所谓的new expression)乃语言内建,咱们是没法改变其行为的,当你写string *ps = new string("Hands up!")时,你所使用的new是所谓的new operator,它其实干了两件事:一、分配足够的内存(实际大小是大于所创建的对象大小)二、调用对象构造函数,转载 2014-06-08 12:43:05 · 546 阅读 · 0 评论 -
Implementation of +,-,*,/ with bitwise operator
There is a question asked on Stackoverflow : Divide a number by 3 without using *,/,+,-,% operators. This question is an Oracle interview question. Some people give excellent answers. You can go the转载 2014-05-30 16:31:08 · 778 阅读 · 0 评论 -
leetcode之Binary Tree Level Order Traversal
题目大意:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9原创 2014-08-01 11:24:02 · 493 阅读 · 0 评论 -
list::splice()函数详解
list::splice实现list拼接的功能。将源list的内容部分或全部元素删除,拼插入到目的list。函数有以下三种声明:void splice ( iterator position, list& x ); // void splice ( iterator position, list& x, iterator i );void splice ( iterator po转载 2014-08-06 21:57:25 · 666 阅读 · 0 评论 -
抽象类与接口的区别及应用
抽象类与接口的区别及应用(本文由张洋提供)抽象类(Abstract Class)与接口(Interface)是面向对象程序设计中两个重要的概念。由于两者在自身特性及应用方法上存在诸多相似性,如都不能实例化、都可以被继承(严格来说对于接口应该叫做实现),这么一来,在许多人心中抽象类与接口的界限非常模糊,对何时该使用抽象类、何时该使用接口更是感到困惑。本文的目的是通过对两者的讨转载 2014-09-11 16:54:24 · 581 阅读 · 0 评论 -
memory pool
动态内存申请预分配中,pinfande原创 2014-10-08 16:42:37 · 682 阅读 · 0 评论 -
宏定义中##的作用
宏定义中的##作用:起到了一种连接符的作用。原创 2014-11-16 20:56:01 · 830 阅读 · 0 评论 -
popen system exec函数
C/C++程序调用shell命令可以通过以下函数实现: FILE *popen(const char *command, const char *mode); popen()会调用fork()产生子进程,然后从子进程中调用/bin/sh -c来执行参数command的指令。参数mode可使用r代表读取,w代表写入。依照mode值,popen()会建立管道连接到子进程的标准输出转载 2015-01-07 22:13:07 · 1266 阅读 · 0 评论 -
单例模式
单例模式是指:在全局范围内,保证一个类只能有一个实例。c++的实现方法:1,构造函数必须是private,保证不可以在类外通过构造函数创建新的对象;2,通过static成员来创建实例;例子:class CSingleton{private: CSingleton() //构造函数是私有的 { } static CSingleton *m_pInstance;publi原创 2015-01-08 19:27:50 · 567 阅读 · 0 评论 -
leetcode之Valid Palindrome
题目大意:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is原创 2014-04-24 19:38:11 · 562 阅读 · 0 评论 -
leetcode之Binary Tree Postorder Traversal和Binary Tree Preorder Traversal
题目意思:这两道题目意思是,对二叉树进行前序遍历和后序遍历。思路:算法本身很简单。算法导论上有伪代码。Postorder Traversal代码:class Solution { public: vector postorderTraversal(TreeNode *root){ travel(root); return output; } void tr原创 2014-04-03 22:10:48 · 573 阅读 · 0 评论 -
leetcode做题思路(一)
reverse words算法思路:1,先对字符串遍历一遍,把每个单词都倒序;2,对整个字符串倒序。用到的东西:1,对字符串倒序:i=x,j=y;i++,j--;2,遍历字符串的过程中,根据空格划分字符串并倒序:用两个标记变量对字符串进行划分。x指向字符串的开始,y移动,一直到遇到空格为止,x和y之间的字符,极为单独的单词。3,对字符传的标准化处理。避免发生的情况是:两个单原创 2014-03-31 20:25:18 · 646 阅读 · 0 评论 -
COM接口映射表
针。class CClassB : public CComObjectRootEx{ BEGIN_COM_MAP(CClassA) COM_INTERFACE_ENTRY(IIntC) COM_INTERFACE_ENTRY(IIntD) COM_INTERFACE_ENTRY2(IDispatch, IIntD)转载 2013-02-03 12:39:42 · 635 阅读 · 0 评论 -
关于INADDR_ANY
是用于多IP机器上 比如你的机器有三个ip 192.168.1.1 202.202.202.202 61.1.2.3 如果你serv.sin_addr.s_addr=inet_addr("192.168.1.1"); 然后监听100端口 这时其他机器只有connect转载 2013-04-01 15:08:07 · 557 阅读 · 0 评论 -
sizeof()用法汇总
sizeof()功能:计算数据空间的字节数1.与strlen()比较 strlen()计算字符数组的字符数,以"\0"为结束判断,不计算为'\0'的数组元素。 而sizeof计算数据(包括数组、变量、类型、结构体等)所占内存空间,用字节数表示。2.指针与静态数组的sizeof操作 指针均可看为变量类型的一种。所有指针变量的sizeof 操作结果均为转载 2013-03-26 08:33:54 · 431 阅读 · 0 评论 -
strcpy、wcscpy与_tcscpy关系 strcpy_s与strcpy比较
C++标准库函数提供了字符和字符串的操作函数,并提供了其UNICODE版本,如:char *strcpy(char *strDestination, const char *strSource); wchar_t *wcscpy(wchar_t *strDestination, const wchar_t *strSource); wcscpy()即为strcpy()的宽字符版本,与_T转载 2013-03-27 22:29:02 · 691 阅读 · 0 评论 -
稀疏图上的Johnson算法
距离上一篇中间时间比较长,按照《算法导论》写了一些C语言实现,不过并没有一一贴上来的打算。这个算法融合了Bellman-Ford算法和Dijkstra算法,并且Dijkstra算法本身还使用了优先级数组(可用二项堆或斐波那契堆实现,这里用的是二项堆实现),性能比较好,达到了O(V2lgV+VE)的时间复杂度,在无负权回路图中是最快的,比较有代表性,因此把我参考自《算法导论》写成的C代码放在这里留档转载 2013-04-30 10:18:50 · 2005 阅读 · 0 评论 -
判断一个图是否有环 无向图 有向图
判断一个图是否有环 无向图 有向图没有找到原文出处,请参考一下链接:http://www.cnblogs.com/hiside/archive/2010/12/01/1893878.htmlhttp://topic.youkuaiyun.com/u/20071023/11/3edb81fc-37b2-4506-906e-44dc0fc521f2.html一、无向图:方法1:转载 2013-05-06 21:35:22 · 1277 阅读 · 0 评论 -
字符串流
1,头文件 #include2,c++标准定义了三种字符串流: istringstream,ostringstream,stringstream3,相关操作: 创建流对象:stringstream strm; //定义流对象 stringstream strm(s); //定义流对象,并初始化,s原创 2014-03-31 10:30:28 · 705 阅读 · 0 评论 -
auto_ptr
C++的auto_ptr所做的事情,就是动态分配对象以及当对象不再需要时自动执行清理。使用std::auto_ptr,要#include 。转载 2014-05-01 21:56:22 · 651 阅读 · 2 评论 -
leetcode之Sort List
1,题目思路:在对链表进行排序,时间复杂度要求O(n log n),空间复杂度要求常量。2,做题思路: 1) 最开始写的代码是用快速排序算法。但时间超过限制。 首先把链表元素放到vector中,然后运用快速排序,对vector中元素进行排序,然后再把vector中元素变换成链表。另,链表直接用快排很不方便。 2)上述算法超过时间限制。后来发现,c++有这个现成算法函数——s原创 2014-04-01 21:32:09 · 739 阅读 · 0 评论 -
malloc/free and new/delete in C++
malloc and free are C++/C language standard library functions, while new/delete are operator of C++. They can be used to allocate dynamic memory and free memory in C++ programsmalloc/free can no转载 2014-05-06 18:04:38 · 663 阅读 · 0 评论 -
leetcode之Palindrome Partitioning
题目大意:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa原创 2014-04-20 16:04:46 · 1290 阅读 · 0 评论 -
leetcode之Palindrome Partitioning II
题目大意:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",R原创 2014-04-20 16:59:05 · 660 阅读 · 0 评论 -
leetcode之Gas Station
题目大意:There are N gas stations along a circular route, where the amount of gas at stationi is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station原创 2014-04-19 22:13:42 · 784 阅读 · 0 评论 -
leetcode之Word Break
题目意思:Given a string s and a dictionary of words dict, determine ifs can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = [原创 2014-04-08 12:49:56 · 792 阅读 · 1 评论 -
leetcode之Max Points on a Line
1,题目意思:在二维平面中,求在一条直线上的点的最大数目2,做题思路: 两层嵌套循环实现,斜率相同的点即为在一条直线上的点,求得最大点数。 需要注意的是: 1)只有一个点时,直接返回1 ; 没有点时,要返回0,因此需要初始化max_num = 0。 2)最里面的循环分三种情况,第一,两个点相同时。第二,垂直于x轴时,斜率不存在。第三,其他,即普通情况。原创 2014-03-31 22:08:51 · 551 阅读 · 0 评论