当前位置: 首页 > news >正文

wordpress 防采集插件seo的基本步骤

wordpress 防采集插件,seo的基本步骤,编写网站代码,东莞做商城网站建设1.前言 http://t.csdnimg.cn/lO4S7 在前文我们已经简单的讲解了二叉树的基本概念,本文将讲解具体的实现 2.基本功能的实现 2.1获取树中节点个数 public int size(TreeNode root){if(rootnull){return 0;}int retsize(root.left)size(root.right)1;return ret;}p…

1.前言

http://t.csdnimg.cn/lO4S7

在前文我们已经简单的讲解了二叉树的基本概念,本文将讲解具体的实现

2.基本功能的实现

2.1获取树中节点个数

    public int size(TreeNode root){if(root==null){return 0;}int ret=size(root.left)+size(root.right)+1;return ret;}public static int nodeSize;public void size2(TreeNode root){if(root==null){return;}nodeSize++;size2(root.left);size2(root.right);}

2.2获取叶子节点的个数

   /*** 求叶子节点个数* @param root* @return*/public int getLeafNodeCount(TreeNode root){if(root==null){return 0;}if(root.left==null&&root.right==null){return 1;}return getLeafNodeCount(root.left)+getLeafNodeCount(root.right);}public int leftSize;public void getLeafNodeCount2(TreeNode root){if(root==null){return;}if(root.left==null&&root.right==null){leftSize++;}getLeafNodeCount2(root.left);getLeafNodeCount2(root.right);}

2.3获取第K层节点的个数

 /*第k层有几个节点*/public int getKLevelNodeCount(TreeNode root,int k){if(root==null){return 0;}if(k==1){return 1;}return getKLevelNodeCount(root.left,k-1)+getKLevelNodeCount(root.right,k-1);}

2.4获取二叉树的高度

 public int getHeight(TreeNode root){if(root==null){return 0;}int leftHeight=getHeight(root.left);int rightHeight=getHeight(root.right);return leftHeight>rightHeight?leftHeight+1:rightHeight+1;}

2.5检测值为value的元素是否存在

 /**** @param root* @param val* @return*/public TreeNode find(TreeNode root,char val){if(root==null){return null;}if(root.val==val){return root;}TreeNode ret=find(root.left,val);if(ret!=null){return ret;}ret=find(root.right,val);if(ret!=null){return ret;}return null;}

2.6判断一棵树是不是完全二叉树

  public boolean isSameTree(TreeNode p,TreeNode q){if(p!=null&&q==null||p==null&&q!=null){return false;}if(p==null&&q==null){return true;}if(p.val!=q.val){return false;}return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);}

3.二叉树的应用 

在知晓了二叉树相关功能的底层实现之后,我们应用二叉树知识来解答

3.1二叉树遍历

二叉树遍历_牛客题霸_牛客网

 

根据题目我们可以知道这其实是两个题目,一是创建二叉树,二是中序遍历结果

所以我们分成两部来完成

先定义二叉树的结构

 class TreeNode {public char val;public TreeNode left;public TreeNode right;public TreeNode(char val) {this.val = val;}}

当不为'#'的时候,我们就创建节点

 public static int i = 0;public static TreeNode createTree(String str) {TreeNode root = null;if (str.charAt(i) != '#') {root = new TreeNode(str.charAt(i));i++;root.left = createTree(str);root.right = createTree(str);} else {i++;}return root;}

最后,我们进行中序遍历——根左子树-根节点-根右子树的顺序来递归即可 

    public static void inorder(TreeNode root){if(root==null){return;}inorder(root.left);System.out.print(root.val+" ");inorder(root.right);}

3.2二叉树的层序遍历

. - 力扣(LeetCode)

这题主要是对二叉树的层序遍历,对于层序遍历是如何遍历的,我们在上文已经讲过——从上而下,自左向右依次遍历.

 在了解到概念之后,我们就可以进行解答了

我们要对知识进行灵活的应用,这种从上而下,自左向右的逻辑与前面所讲到的栈和队列知识中队列先进先出逻辑类似,所以我们可以用创建队列来解答

1.是否为空,若为空,则返回空列表

2.若不为空,则进入循环判断(当队列为空则跳出循环),创建一个列表来打印每层的结果

3.将每层结果存入ret,最后返回ret即可

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public List<List<Integer>> levelOrder(TreeNode root) {List<List<Integer>> ret=new ArrayList<>();if(root==null){return ret;}Queue<TreeNode> queue = new LinkedList<>();queue.offer(root);while(!queue.isEmpty()){int size=queue.size();List<Integer> list=new ArrayList<>();//每层while(size>0){TreeNode cur=queue.poll();list.add(cur.val);if(cur.left!=null){queue.offer(cur.left);}if(cur.right!=null){queue.offer(cur.right);}size--;}ret.add(list);}return ret;}
}


对二叉树的基础知识讲解就到这里,如果上述内容对您有帮助,希望给个三连谢谢!

 

http://www.hkea.cn/news/145237/

相关文章:

  • wordpress 网站备份厦门seo外包服务
  • 网站建设及推广培训杭州百度快照优化排名
  • 简单手机网站开发软件关键词排名代发
  • visio画网站开发类图注册域名后怎么建网站
  • 道里网站运营培训北京网络营销咨询公司
  • 目前做网站流行的语言seo关键词排名优化哪家好
  • 长沙营销型网站制作费用seo图片优化
  • 学生诚信档案建设网站seo数据分析
  • 北京住房城乡建设厅网站首页1688官网入口
  • 网站建设需要懂什么软件徐州百度seo排名优化
  • wordpress网站样式网站排名查询
  • 郑州网站建设推销外贸网站推广与优化
  • 当当网站开发系统说明搜索引擎排名google
  • 国外男女直接做的视频网站企业邮箱登录入口
  • 成都可以做网站的公司百度手机助手最新版下载
  • 赤峰网站建设招聘市场营销互联网营销
  • 网站开发后端需要哪些技术友情链接检索数据分析
  • 金华竞价排名 金华企业网站建设常见的网络营销平台有哪些
  • p2p网站开发关键词seo是什么意思
  • 自己免费怎么制作网站合肥今天的最新消息
  • 今日头条新闻10条简短seo网络优化招聘信息
  • 赣州人才网官方网站关键词seo优化软件
  • cad做兼职区哪个网站郑州网络营销公司排名
  • 宁夏银川做网站的公司有哪些网络营销分类
  • 换物网站为什么做不起来中国免费广告网
  • 可以显示一张图片的网站怎么搭建搜索引擎优化策略
  • 精品课程网站建设论文今天的新闻最新消息
  • 检查网站收录问题蚌埠seo外包
  • 建站展示网站优化网
  • 秦皇岛网站建设价格深圳seo公司