Ubuntu下禁用笔记本自带键盘
All rights reserved by DianeSoHungry (Qingyun Hu).
Original URL: https://www.cnblogs.com/DianeSoHungry/p/8891148.html
Contents
- Construct a binary tree from DLR and LDR traversals.
Problem 1
Construct a binary tree from DLR and LDR traversals.
(根据先序遍历和中序遍历序列,建二叉树)
Example:
Input:
8
1 2 4 7 3 5 6 8
4 7 2 1 5 3 8 6
Output:
Head pointer of the built binary tree
Intuition
For each DLR, you know the first element correspond to the root node. By finding the first element of DLR in LDR, you can split out the subarray of DLR and LDR for left subtree, so as to the subarray of DLR and LDR for right subtree. That is, time for recursion.
Solution in CPP
#include<iostream>
#include<queue>
struct BtNode{
int val;
BtNode* left;
BtNode* right;
BtNode(int val): val(val), left(nullptr), right(nullptr){
};
};
BtNode* BuildBT(int pre[], int mid[], int len){
if (len == 0) {
return nullptr;
}
BtNode* root;
for (int i = 0; i < len; ++i) {
if ( mid[i] == pre[0]) {
root = new BtNode(mid[i]);
root->left = BuildBT(pre+1, mid, i);
root->right = BuildBT(pre+i+1, mid+i+1, len-i-1);
break;
}
}
return root;
}
void TraverseLevelwise(BtNode* bt){
std::queue<BtNode*> q;
q.push(bt);
while (!q.empty()) {
if (q.front() != nullptr) {
std::cout << (q.front()->val) << " ";
q.push(q.front()->left);
q.push(q.front()->right);
}
else {
// std::cout << "null ";
}
q.pop();
}
std::cout << std::endl;
}
int main(){
int n;
std::cin >> n;
int preorder[n];
int midorder[n];
for (int i = 0; i < n; ++i) {
std::cin >> preorder[i];
}
for (int i = 0; i < n; ++i) {
std::cin >> midorder[i];
}
BtNode* res = BuildBT(preorder, midorder, n);
TraverseLevelwise(res);
return 0;
}
After getting the binary tree, for checking, the level order of the tree is printed as below.
1 2 3 4 5 6 7 8
Reference
《剑指offer》
Ubuntu下禁用笔记本自带键盘的更多相关文章
- ubuntu禁用笔记本自带键盘
ubuntu如何禁用笔记本键盘 打开终端运行命令 xinput list Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core ...
- deepin禁用笔记本自带键盘
参考命令: sudo apt install xinput xinput xinput list-props 'AT Translated Set 2 keyboard' xinput set-pro ...
- Linux下禁用笔记本触摸板
1 概述 在Linux下禁用触摸板的方法有很多,这里列举三种: 图形界面配置关闭 modprobe关闭 xinput关闭 2 图形界面配置关闭 笔者的环境为Manjaro+Xfce,其他的桌面也应该类 ...
- 在ubuntu下关闭笔记本触摸板
http://www.cnblogs.com/icejoywoo/archive/2011/04/14/2016318.html 原文地址:http://forum.ubuntu.org.cn/vie ...
- ubuntu下禁用和恢复触摸板
1.一般禁用选项在 settings > mouse and touchpad 中.(16.04通过实验)如果无法禁用或者希望恢复,向下看. 2.命令行键入: xinput ,插卡touchpa ...
- centos系统下禁用笔记本触控板
最近把零几年的老爷笔记本拿出来用,使用windows系统实在太卡了,于是折腾安装上Centos系统了,但是在使用的过程中发现鼠标经常失效.使用了多种方法(比如:http://blog.csdn.net ...
- linux 关闭笔记本自带键盘
linux 命令行工具 xinput list 找到 AT Translated Set 2 keyboard,其 id为 13 设置值为 0 xinput 如果想恢复,对应的值设为1即可 xinpu ...
- Ubuntu下如何禁用IPv6
Ubuntu下如何禁用IPv6 2013-10-16 11:32:02 分类: HADOOP 分布式下的hadoop/hbase运行总出问题,zookeeper连接总是出问题,怀疑可能是ip ...
- 一个禁用mac内置键盘的方法
一个禁用mac内置键盘的方法 强大的 karabiner, 非常好用. 可以直接在有外接键盘连接的情况下, 禁用掉内置键盘 另外一个方法是启用mac的 鼠标键, 感觉用处不是很大, 修饰健并没有被禁用 ...
随机推荐
- C#中索引器的实现过程,是否只能根据数字进行索引?
描述一下C#中索引器的实现过程,是否只能根据数字进行索引? 答:索引器是一种特殊的类成员,它能够让对象以类似数组的方式来存取, 使程序看起来更为直观,更容易编写,可以用任意类型.
- 前端框架之bootstrap及相关技术网站
1.web框架之bootstrap bootstrap来源Twitter,是一个CSS/HTML框架,它是基于HTML,CSS,JavaScript下的,使用简洁,当中提供了很多HTML和CSS 如用 ...
- 你可能不知道的 new.target
new 是构造函数生成实例的命令, ES6为 new 命令引入了 new.target属性.这个属性用于确定构造函数是怎么调用的. 在构造函数中, 如果一个构造函数不是通过 new操作符调用的, ne ...
- POJ的层次感分类
转载自:[http://blog.csdn.net/zzycsx/article/details/49103451] OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,po ...
- Oracle口令文件管理
Oracle的口令文件目录 $ORACLE_HOME/dbs/orapw$ORACLE_SID 建立口令文件 orapwd file=$ORACLE_HOME/dba/orapw$ORACLE_SID ...
- Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; 没有sessionFactory
maven子项目spring配置文件创建bean 没有找到另一个子项目中的bean. 需要引入另一个子项目的配置文件,仅提供测试用 如下: <!-- 仅供测试用 --> <impor ...
- 《Linux就该这么学》,刘小伙实在人,给打个广告
本书是由全国多名红帽架构师(RHCA)基于最新Linux系统共同编写的高质量Linux技术自学教程,极其适合用于Linux技术入门教程或讲课辅助教材,目前是国内最值得去读的Linux教材,也是最有价值 ...
- 在win10上同时安装Python2/Python3
如何在win10上同时安装python2和python3? 为了满足日常工作或者学习的需要,我们可能会经常用到python2和python3,下面是给大家在win10上同时安装两个版本的python的 ...
- xml中Node和Element的区别
本文转载自:http://blog.csdn.net/wcydiyi/article/details/4432636点击打开链接 1.元素(Element)和结点(Node)的区别: ...
- 谈一谈如何远程访问MySQL(腾讯云,云主机)
连接MySQL (其他的sql 基本相同套路) 腾讯云不管怎么设置端口和MySQL权限以及监听端口就是不能连接? 远程访问MySQL数据库的几个关键点 端口设置 数据库权限设置 数据库的监听端口设置 ...