日期: 2022-09-20 15:33:51 浏览数:5

上往建站提供服务器空间服务商,百度快照排名,网站托管,百度推广运营,致力于设计外包服务与源代码定制开发,360推广,搜狗推广,增加网站的能见度及访问量提升网络营销的效果,主营:网站公司,百度推广公司电话,官网搭建服务,网站服务企业排名,服务器空间,英文域名等业务,专业团队服务,效果好。
新安网站优化【新安开通400电话】新安网站搭建、新安微信公众号推文外包、新安开通京东拼多多设计、新安淘宝装修
新安县位于河南省洛阳市西部,地处北纬34°36′至北纬35°05′,东经111°53′至112°19′之间。北临黄河,与济源市及山西省垣曲县隔河相望;南与宜阳县接壤;西与渑池县及义马市为邻;东与洛阳市孟津区等 [27] 毗连。
新安历为十三朝古都洛阳畿地和西方门户,地扼函关古道,东连郑汴,西通长安,自古为中原要塞,军事重地。当代,陇海铁路及310国道、连霍高速公路横贯东西,更成为连接祖国西北、华东及华北间的重要通道。
新安不仅是河南省48个扩权县和50个对外开放重点县之一,也被誉为中西部地区发展潜力最大、最具活力的县市之一。 [1] 2020年7月29日,入选2019年重新确认国家卫生乡镇(县城)名单。 [2] 2020年11月,入选第六届全国文明城市 [3] 。
2020年11月,入选 “2020年中国工业百强县(市)”,排名第84位。 [4] 11月27日,被评为省级森林城市 [5] 。
2020年,新安县完成地区生产总值530亿元,同比增长4%,一般公共预算收入28.14亿元,同比增长5.9%;规模以上工业增加值同比增长4.7%;固定资产投资同比增长7.1%;社会消费品零售总额完成112.4亿元;城乡居民人均可支配收入分别达到38312元、18596元。 [29]
树的三种遍历方式
前序遍历(NLR——Preorder Traversal)也叫先序遍历,先访问左子树,在访问根节点,最后访问右子树
口诀:左根右
中序遍历(LNR——Inorder Traversal),先访问根节点,后访问左子树和右子树
口诀:根左右
后序遍历(LRN——Postorder Traversal),先访问叶子及诶单。从左子树到右子树
左右根
前序遍历:
中序遍历:
后序遍历:
代码实现:
// 前序遍历
let preOrderTraverseNode = function (node, callback) {
if (node !== null) {
callback(node.element);
preOrderTraverseNode(node.prev, callback);
preOrderTraverseNode(node.next, callback);
}
};
// 中序遍历
let inOrderTraverseNode = function (node, callback) {
if (node !== null) {
inOrderTraverseNode(node.prev, callback);
callback(node.element);
inOrderTraverseNode(node.next, callback);
}
};
// 后续遍历
let postOrderTraverseNode = function (node, callback) {
if (node !== null) {
postOrderTraverseNode(node.prev, callback);
postOrderTraverseNode(node.next, callback);
callback(node.element);
}
};
树的常用操作
搜索树中的最小值
搜索树中的最大值
搜索树中的特定值
删除节点
搜索树中的最小值
遍历左子树,找到最后一个子节点
代码实现:
let minNode = function (node) {
if (node === null) return null;
while (node && node.prev !== null) {
node = node.prev;
}
return node;
};
搜索树中的最大值
遍历右节点,直到找到最后一个子节点
代码实现:
`let maxNode = function (node) {
if (node === null) return null;
while (node && node.next !== null) {
node = node.next;
}
return node;
};`
搜索树中的特定值
第三种方式是搜索特定的值,我们需要比较要搜索的值与当前节点的值,如果要搜索的值小于当前节点的值,则从当前节点开始递归查找左子数(左子节点)。如果要搜索的值大于当前节点的值,则从当前节点开始递归查找右子树(右子节点)
代码实现:
let searchNode = function (node, key) {
if (node === null) return null;
if (key < node.element) return searchNode(node.prev, key);
else if (key > node.element) return searchNode(node.next, key);
else return node;
};
删除节点
如果删除的节点为叶子节点,则直接删除它
如果删除的节点只有一个子节点,则直接删除节点的父节点,指向其子节点
如果待删除的节点包含两个子节点,我们选择右子树上最小值创建一个临时子节点,然后复制到待删节点,然后删除最小子节点。
第十一章: 二叉堆和堆排序
二叉堆概述和特点
二叉堆是一种特殊的二叉树
也就是堆的数据结构,也叫做二叉堆,能高效的查找出最大值和最小值
常被应用于优先队列中,也经常被用在注明的堆排序算法中
特点:
二叉堆是一颗完全二叉树,完全二叉树表示树的每一层都有左子树和右子树,(除了最后一层叶子节点),并且最后一层至少都哟一个左子树,
这叫结构特性
二叉堆不是最小堆就是最大堆,最小堆允许快速找出最小值,最大堆允许找出最大值,所有的节点都大于等于(最大堆)或小于等于(最小堆)的每个子节点,
这叫堆特性
二叉堆的实现
最小堆:
class MinHeap{
constructor() {
this.heap = []
}
// 替换两个节点值
swap(i1,i2){
const temp = this.heap[i1];
this.heap[i1] = this.heap[i2];
this.heap[i2] = temp;
}
// 获取父节点
getParentIndex() {
return (i -1) >> 1; //求除2的商
}
// 获取左节点
getLeftIndex() {
return i * 2 + 1; //求除2的商
}
// 获取右节点
getRightIndex() {
return i * 2 + 2; //求除2的商
}
// 上移
shiftUp(index) {
if(index == 0) {return;}
const parentIndex = this.getParentIndex(index);
if(this.heap[parentIndex] > this.heap[index]) {
this.swap(parentIndex,index);
this.shiftUp(parentIndex);
}
}
// 下移
shiftDown() {
const leftIndex = this.getLeftIndex(index);
const rightIndex = this.getRightIndex(index);
if(this.heap[leftIndex] < this.heap[index]) {
this.swap(leftIndex,index);
this.shiftDown(leftIndex);
}
if(this.heap[rightIndex] < this.heap[index]) {
this.swap(rightIndex,index);
this.shiftDown(rightIndex);
}
}
// 插入
insert(value) {
this.heap.push(value);
this.shiftUp(this.heap.length - 1);
}
// 删除堆顶
pop() {
this.heap[0] = this.heap.pop();
this.shiftDown(0);
}
// 获取堆顶
peek() {
return this.heap[0];
}
// 获取堆的大小
size() {
return this.heap.length;
}
}
const h = new MinHeap();
h.insert(3);
h.insert(2);
h.insert(1);
h.pop();
参考代码:
JavaScript 实现:最小堆类
最大堆:
let heap = [];
function swap(index1, index2) {
let temp;
temp = heap[index1];
heap[index1] = heap[index2];
heap[index2] = temp;
}
function shiftup(index) {
let parentIndex = (index - 1) >> 1// Math.floor((index - 1) / 2);
if (index != 0 && heap[parentIndex] < heap[index]) {
swap(parentIndex, index);
shiftup(parentIndex);
}
}
function shiftDown(index) {
let leftNodeIndex = (index + 1) * 2 - 1, rightNodeIndex = (index + 1) * 2
if (leftNodeIndex < heap.length && heap[leftNodeIndex] > heap[index]) {
swap(leftNodeIndex, index);
shiftDown(leftNodeIndex);
} else if (rightNodeIndex < heap.length && heap[rightNodeIndex] > heap[index]) {
swap(rightNodeIndex, index);
shiftDown(rightNodeIndex);
}
}
function insert(val) {
heap.push(val);
shiftup(heap.length - 1);
}
function remove() {
swap(0, heap.length - 1);
heap.pop();
shiftDown(0);
return heap[0];
}
insert(1);
insert(3);
insert(2);
insert(5);
remove();
insert(4);
insert(6);
remove();
console.log(heap);//[ 4, 3, 2, 1 ]

新安网站优化【新安开通400电话】新安网站搭建、新安微信公众号推文外包、新安开通京东拼多多设计、新安淘宝装修
上往建站提供搭建网站,域名注册,官网备案服务,网店详情页设计,企业网店,专业网络店铺管理运营全托管公司咨询电话,服务器空间,微信公众号托管,网页美工排版,致力于域名申请,竞价托管,软文推广,全网营销,提供标准级专业技术保障,了却后顾之忧,主营:虚拟主机,网站推广,百度竞价托管,网站建设,上网建站推广服务,网络公司有哪些等业务,专业团队服务,效果好。
服务热线:400-111-6878 手机微信同号:18118153152(各城市商务人员可上门服务)