
递归/回溯
L_Aster
..
展开
-
前序、中序、后序相互转化的C代码简单递归实现
已知前序、中序求后序#include <stdio.h>void PreAndInToPost(char *preorder,char *inorder,int lenth){ if(lenth==0) return; char temp=*preorder; int rootindex=0; while(*preorder!=inorder[ro原创 2016-10-25 22:08:30 · 1118 阅读 · 0 评论 -
汉诺塔递归C语言代码实现
#include <stdio.h>int c=0;void move(int disk,char start,char end){ printf("step:%d,move %c to %c\n",++c,start,end); return;}void hanoi(int n,char A,int B,char C){ if(n==1) mov原创 2016-10-29 16:39:52 · 9014 阅读 · 0 评论 -
n皇后问题—回溯法 C++实现
#include #include using namespace std;bool isLegal(int row,int col,vector &v,int n){ for(int i=0;i<row;++i) if(v[i][col]=='Q') return false; for(int i=row-1,j=col-1;i>=0&&j>=0;--i,--j)原创 2017-09-02 22:18:13 · 3502 阅读 · 0 评论