#include
#include
using namespace std;
//下面一个移位是一样的,>>相当于除去2,主要是要用right-left,否则对于大数据来说会产生溢出问题。切记
int binarySearch(int arr[],int len,int number)
{
int left=0;
int right=len-1;
in...
分类:
其他好文 时间:
2014-05-15 07:14:38
阅读次数:
272
题意:给定一棵perfect binary tree,将它每一个节点的next指针都指向该节点右边的节点
思路:dfs
在connect一棵树的时候,需要知道这棵树的根节点和它右边的节点
1.将树的根节点和它右边的节点连接起来
2.递归地将左子树connect起来,需要知道左子树节点和右子树节点
3.递归地将右子树connect起来,需要知道右子树节点和根右边的节点的左子树节点
递归函数为:
void connect(TreeLinkNode *root, TreeLinkNode *sibling)
表...
分类:
其他好文 时间:
2014-05-15 07:14:04
阅读次数:
289
题意:判断一个链表中是否有环
思路:快慢指针,如果有环,最终快慢指针会在非NULL相遇
注:用到fast->next前先要确保fast非NULL,要用fast->next->next前先要确保fast,fast->next非NULL
复杂度:时间O(n), 空间O(1)
相关题目:Linked List CycleII...
分类:
其他好文 时间:
2014-05-15 07:01:57
阅读次数:
219
Robot Motion
Problem Description
A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The...
分类:
其他好文 时间:
2014-05-15 05:48:40
阅读次数:
346
1、
??
Populating Next Right Pointers in Each Node
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate...
分类:
其他好文 时间:
2014-05-15 04:57:36
阅读次数:
221
题目
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorted from left to right.The first integer...
分类:
其他好文 时间:
2014-05-15 03:41:11
阅读次数:
257
//***************************************************************
//结构体:简单的静态链表
#include
#include
#define NULL 0
#define SIZE 10
struct student
{
char num[SIZE];
float score;
struct student *next;
...
分类:
编程语言 时间:
2014-05-15 02:55:09
阅读次数:
359
1关于greenletgreelet指的是使用一个任务调度器和一些生成器或者协程实现协作式用户空间多线程的一种伪并发机制,即所谓的微线程。greelet机制的主要思想是:生成器函数或者协程函数中的yield语句挂起函数的执行,直到稍后使用next()或send()操作进行恢复为止。可以使用一个调..
分类:
其他好文 时间:
2014-05-14 19:09:00
阅读次数:
427
staticint_osip_message_parse(osip_message_t*sip,constchar*buf,size_tlength,intsipfrag){inti;constchar*next_header_index;char*tmp;char*beg;tmp=osip_malloc(length+2);if(tmp==NULL){OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"Couldnotallocatememory..
分类:
其他好文 时间:
2014-05-14 16:06:25
阅读次数:
296
还没有处理lambda、上下文等,有待完善。
main
{
for
putsl(eval(getsl))
}
rstr eval(rstr s)
{
s=tokenize(s)
v=s.split(' ')
if v.get(0)!='('
return v.get(0)
next=find(v.sub(2))+2
switch v.get(1)
case '+'
r...
分类:
其他好文 时间:
2014-05-14 15:32:34
阅读次数:
323