自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(10)
  • 收藏
  • 关注

转载 一个简单smart pointer的实现

转自出处  学习这个代码有助于理解shared_ptr指针的实现方法  smart.cpp  1 namespace smart  2 {  3     // 引用计数类.  4      class smart_count  5     {  6     public:  7         smart_count(int c = 0) : use

2012-07-29 01:09:18 2123

原创 根据一个已排序数组构造一棵二叉树,要求树的高度最少

Node* creatBTree(int *pArray, int startPos, int endPos){ if (endPos < startPos) { return NULL; } if (startPos == endPos) { Node* pNode = new Node(pArray[startP

2012-07-26 00:36:11 1268

原创 判断一颗二叉树是否是平衡二叉树

方法一,参考 http://blog.csdn.net/forestlight/article/details/6575507templatetypename T>  int DepthTree(BSTreeNode *pbs)  {      if (pbs==NULL)          return 0;      else      {

2012-07-25 01:10:40 1626 1

原创 对一个栈的元素进行从小到大的排序

stack sortStack(stack &s){ stack nS; while (!s.isEmpty()) { int tmp = s.pop(); while (!nS.isEmpty() && nS.top < tmp) { s.push(nS.pop()); }

2012-07-25 00:33:13 1495

原创 查找BST中第 Kth 大的元素

其实整个算法用到的是中序遍历的思想,只不过是先遍历右子树,然后遍历根节点,再遍历右子树,每次遍历一个节点的时候thK减1,当thK为0时,就是需要找的节点Node* findKthNodeImp(Node *pNode, int& thK){ if ((pNode == NULL)|| (thK <= 0)) { return NULL; }

2012-07-15 15:32:37 690

原创 返回数组中第二大的数

int findSecondLarge(int *a, int N){ int max1=a[0]; int max2=0; for (int i=1; i < N; i++) { if (a[i] > max1) { max2=max1; max1=a[i]; }

2012-07-12 23:59:07 1886

原创 求中序遍历的下一个节点

转自出处Node *findInOrderSuccessor(Node *root, Node *target){ Stack s; Node *cur = root; Node *prev = NULL; while(true){ while(cur) { s.push(cur);

2012-07-12 23:19:28 1019

转载 在两个有序的数组中找第N个数,O(lgm+lgn)级

转自出处问题描述:Give a divide and conquer algorithm for the following problem:you are given two sorted lists of size m and n, and are allowed unit time access to the ith element of each lis

2012-07-11 00:28:36 2337

原创 编写代码实现删除一个字符串中连续出现超过一次的空格

// delete the blank.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include char MyArray[] = " I XX abcd, abcd is just a bold shit";char *myMemCpy

2012-07-04 00:57:34 975

转载 遍历n个元素, 等概率随机取出其中之一元素

转自出处问题描述1.一个文件中含有n个元素,只能遍历一遍,要求等概率随机取出其中之一。    先讲一个例子,5个人抽5个签,只有一个签意味着“中签”,轮流抽签,那么这种情况,估计这5个人都不会有异议,都觉得这种方法是公平的,这确实也是公平的,“抓阄”的方法已经有很长的历史了,要是不公平的话老祖先们就不干了。    或许有人觉得先抓的人中签的概率会大一些,

2012-07-04 00:25:57 1736

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除