C语言实现二叉树的遍历二叉树结点的定义/*
先序,中序,后序的遍历时间复杂度为O(n),每个结点只访问一次。 层序的时间复杂度最差为O(n^2),当二叉树基本平衡时,时间复杂度为O(n) n为结点个数
*/typedef int tree_node_element;
/**
* @author 韦轩
* @time 2015/07/11
* @brief 二叉树的结点数据结...
分类:
其他好文 时间:
2015-07-13 22:35:19
阅读次数:
205
/** * @author 黄志伟 */public class Search{ public static void main(String[] args){ Node A = new Node(); A.setValue(51); Node B =...
分类:
其他好文 时间:
2015-07-13 20:22:07
阅读次数:
141
内容提要通过递归对列表进行遍历,从而完成各种操作。member/2这个谓词逻辑通过递归遍历了列表,对列表头部有一些操作,然后递归地对列表尾部做另外一些相同的操作。通过递归遍历列表在Prolog是十分普遍的做法,事实上,我们必须要掌握这项技能。所以我们学习如下的例子。当我们使用列表的时候,我们经常会将...
分类:
其他好文 时间:
2015-07-13 13:38:09
阅读次数:
142
该题的思路很简单,就是对BST进行先序遍历,找到第k个数的时候返回。这里借助栈用迭代实现,递归的代码更简单,没有尝试。
class Solution {
public:
int kthSmallest(TreeNode* root, int k) {
stack cache;
TreeNode *point = root;
TreeNode...
分类:
其他好文 时间:
2015-07-12 17:27:38
阅读次数:
85
Java遍历文件夹的方法有多种,之前我写了一种遍历文件夹的方法点击,使用File类的方法递归遍历,这次是使用Java7提供的新的方法遍历文件夹。
File提供两个方法遍历文件夹,
上面两个方法都需要FileVisitor参数,FileVisitor代表一个文件访问器,walkFileTree()方法会自动遍历start路径下的所有文件和子目录,遍历文件和子目录都会触发FileV...
分类:
编程语言 时间:
2015-07-10 15:27:48
阅读次数:
150
基本思想就是:二叉树的中序非递归遍历 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *...
分类:
其他好文 时间:
2015-07-07 00:56:35
阅读次数:
114
题目:
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
解题:
求最大深度 和前面一题类似 用递归遍历就...
分类:
编程语言 时间:
2015-07-06 16:06:14
阅读次数:
143
#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"
typedef struct lNode
{
char data;
struct lNode *lchild;
struct lNode *rchild;
}LNODE,*Tree;
typedef struct Node
{
Tree data;
struct Node * Next;
}NODE, * PNODE;
typedef struct Stack
{
...
分类:
其他好文 时间:
2015-07-02 19:30:39
阅读次数:
135
原题如下:
Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).我的算法:
1. 首先获得树的高度
2. 层序递归遍历二叉树实现如下:package leet...
分类:
其他好文 时间:
2015-06-29 15:02:29
阅读次数:
130
import java.io.File;
public class Test {
/**
* @param args
* @author itmyhome
*/
public static void main(String[] args) {
File f = new File("F:/javaAPI/JavaAPI1.6/java/awt");
printFile(f...
分类:
编程语言 时间:
2015-06-25 23:04:00
阅读次数:
302