![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
递归专项
人面桃花相映红
BNU student
展开
-
单链表的归并排序和快速排序
1.快速排序 首先:对于数组的快速排序思想是先找到一个left和一个right和一个基数,然后按照两个指针的相向运动并按照一定的规律交换值,最后找到一个支点,使得支点左边的值都小于支点,支点右边的值都大于支点。 但是单链表没有pre指针,如何找到这个支点呢? 我们只需要两个指针p和q,两个指针都往next的方向移动,移动的过程中始终保持p之前的key都小于选定的key,p和q之间的key都大于key,当q走到末尾的时候,就完成了支点的寻找。 代码如下: struct node {原创 2020-11-29 20:19:19 · 238 阅读 · 0 评论 -
递归的思想生成排列组合
#include<iostream> #include<stdio.h> #include<stdio.h> #include<string> #include<algorithm> using namespace std; int m,n,a[10]; bool vis[10]; int ans [10]; void dfs(int x) //从m个数中选出来n个数的字典序排列,并且数目不可重原创 2017-03-11 20:27:59 · 443 阅读 · 0 评论 -
文章标题
7.标题:六角填数如图【1.png】所示六角形中,填入1~12的数字。 使得每条直线上的数字之和都相同。 图中,已经替你填好了3个数字,请你计算星号位置所代表的数字是多少? 请通过浏览器提交答案,不要填写多余的内容。 暴力解题,按照图示的变量命名来#include<iostream> #include<stdio.h> #include<algorithm> #include<string> #i原创 2017-03-11 21:11:48 · 134 阅读 · 0 评论 -
八皇后问题 递归搜索
题意:八皇后问题,在同一行,同一列,对角线上不能放皇后,求一共有多少种放的方法。#include<iostream> #include<stdio.h> #include<string> #include<algorithm> #include<math.h> using namespace std; int r[20] ; //表示 int cnt = 0; int n = 8; //默认的八行八原创 2017-04-06 21:11:17 · 365 阅读 · 0 评论 -
uva 514
题意大家都知道了,就是a站是顺序进入,b站是按照题目中输入的那样离开; 很明显,这是我们学习的栈的用法。 分析:一共有两种情况,第一种就是进站之后就直接离开;第二种就是进站,然后等着,直到和出栈的顺序相等的时候再出栈。 只要处理好这两个就可以了; #include #include #include using namespace std; int ans[10000]; int ma原创 2017-08-19 17:42:02 · 287 阅读 · 0 评论 -
leetcode 101 对称二叉树
给定一个二叉树,检查它是否是镜像对称的。 例如,二叉树[1,2,2,3,4,4,3]是对称的。 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个[1,2,2,null,3,null,3]则不是镜像对称的: 1 / \ 2 2 \ \ 3 3 1.用递归的思想 C++ /** * D...原创 2019-04-10 18:53:55 · 95 阅读 · 0 评论