我刚在.Net下做了测试,对于尾递归,在Debug模式下,不会被优化为非递归结构,在Release模式下,会被优化为非递归结构,就不存在栈溢出的问题了 STST 这是我模拟的文件结构类 STST 这是非尾递归版本 STST 这是尾递归版本 STST 这是测试代码 STST 这是CreateDir的定...
分类:
其他好文 时间:
2015-10-25 13:29:04
阅读次数:
239
/*二叉树遍历(递归版本&非递归版本)(1)中序遍历(2)先序遍历(3)后续遍历*/struct BinTree { int data; /*数据域*/ BinTree* leftchild; /*左孩子*/ BinTree* rightchild; ...
分类:
其他好文 时间:
2015-09-13 11:48:50
阅读次数:
125
简单的0-1背包打印路径问题,我们可以记录一个p[][]数组来判断,当前物品是否被选中,最后按照记录输出,注意是逆序。
#include
#include
int main()
{
int a[25],p[25][10005],i,j,n,m,s[10005];
while(scanf("%d%d",&m,&n)!=EOF){
for(i=...
分类:
其他好文 时间:
2015-08-31 01:16:33
阅读次数:
308
typedef int ElemType;
【递归版本】
int binSearch2(ElemType List[] ,int x,int head,int tail){ //递归版本
while(head<=tail){
int mid=(head+tail)/2;
if(List[mid]==x){
return mid;
}
else if(Li...
分类:
其他好文 时间:
2015-08-07 13:24:57
阅读次数:
115
翻转一棵二叉树样例 1 1
/ \ / 2 3 => 3 2
/ 4 4
递归版本先翻转左子树,后翻转右子树,然后对整个树进行翻转void swapTree(TreeNode *&root){
TreeNode *tmp = root->left;
root->left = root->right...
分类:
其他好文 时间:
2015-07-31 16:14:59
阅读次数:
112
快速排序
/*
实现快速排序的非递归版本
*/
#include
#include
#include
#include
#include
using namespace std;
#define MAX 100
typedef struct node
{
int nLow;
int nHigh;
}data;
template
int Partition(vector vect ...
分类:
编程语言 时间:
2015-07-28 01:01:55
阅读次数:
137
递归版package MergeSort;import Utils.SortUtils;
/**
* 归并排序递归版
* @author liguodong
*/public class Demo02 { public static void mergeSort(int[] a){
mSort(a, a, 0, a.length-1);
}
/**...
分类:
编程语言 时间:
2015-07-26 22:41:45
阅读次数:
230
递归版本的实现:
long long int Pow1(int x,unsigned int N)
{
if (N == 0)
{
return 1;
}
if (N & 0x01)
{
return Pow(x * x,N >> 1) * x;
}
else
return Pow(x * x,N >> 1);
}递归 的基准条件是:N==0 此时返回1(不调用自身...
分类:
其他好文 时间:
2015-07-22 19:05:37
阅读次数:
199
#include
using namespace std;
//归并排序非递归版。
void Sort(int a[], int n,int high)
{
int k;
for (int i = 0; i < high; i += 2 * n)
{
int x = i;//001
int y = i + n;//2 2...
分类:
编程语言 时间:
2015-07-19 21:47:06
阅读次数:
140
递归的划分 比较容易理解 但是要time out若要把n用不大于n的数m划分总共分四种情况1.若n==m 则只有一种 但是要继续递归 所以等于 1+q(n,m-1)2.若nm 则有两种情况 1.用m划分 剩余则是n-m 因此等于 q(n-m,m) 2.用小于m的数继续划分 则是...
分类:
其他好文 时间:
2015-07-15 22:34:24
阅读次数:
237