中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

如何做自己的網(wǎng)站后臺網(wǎng)絡(luò)營銷的方式與手段

如何做自己的網(wǎng)站后臺,網(wǎng)絡(luò)營銷的方式與手段,做網(wǎng)站大概需要幾個(gè)人,網(wǎng)站開發(fā)選題背景文章目錄 一、二叉搜索樹的概念結(jié)構(gòu)和時(shí)間復(fù)雜度二、二叉搜索樹的插入三、二叉搜索樹的查找四、二叉搜索樹的刪除(最麻煩,情況最多,一一分析)3.1首先我們按照一般情況下寫,不考慮特殊情況下4.1.1左為空的情況&#xff…

文章目錄

    • 一、二叉搜索樹的概念結(jié)構(gòu)和時(shí)間復(fù)雜度
    • 二、二叉搜索樹的插入
    • 三、二叉搜索樹的查找
    • 四、二叉搜索樹的刪除(最麻煩,情況最多,一一分析)
      • 3.1首先我們按照一般情況下寫,不考慮特殊情況下
        • 4.1.1左為空的情況(與右為空的情況差不多)
        • 4.1.2兩邊都不為空的情況下
      • 4.1其次我們考慮極端情況,如果剛好是整體樹的根要刪除
    • 五、二叉搜索樹的中序遍歷
    • 六、二叉搜索樹的拷貝構(gòu)造函數(shù),析構(gòu)函數(shù),賦值操作
      • 6.1 賦值操作(比較簡單)
      • 6.2拷貝構(gòu)造
      • 6.3析構(gòu)函數(shù)
    • 七、全部源碼展現(xiàn)(遞歸玩法的代碼也傳進(jìn)來了,下次講解)

在這里插入圖片描述


先贊后看,養(yǎng)成習(xí)慣!!!^ _ ^<3 ?? ?? ??
碼字不易,大家的支持就是我堅(jiān)持下去的動力。點(diǎn)贊后不要忘了關(guān)注我哦!
所屬專欄:C++進(jìn)階
在這里插入圖片描述

一、二叉搜索樹的概念結(jié)構(gòu)和時(shí)間復(fù)雜度

二叉搜索樹(Binary Search Tree)又稱二叉排序樹(Binary Sort Tree),是一種特殊類型的二叉樹,它所有的根節(jié)點(diǎn)大于左子樹的節(jié)點(diǎn),小于右子樹的節(jié)點(diǎn),對二叉搜索樹進(jìn)行中序遍歷,即可得到有序的數(shù)列。二叉搜索樹的時(shí)間復(fù)雜度由樹的高度決定,其搜索、插入和刪除的時(shí)間復(fù)雜度均為 O(log n),其中 n 是節(jié)點(diǎn)數(shù)。在最壞的情況下,仍然會有 O(n)的時(shí)間復(fù)雜度。
在這里插入圖片描述

二、二叉搜索樹的插入

首先定義一個(gè)命名空間作用域,在域中進(jìn)行插入操作,構(gòu)造一個(gè)二叉樹的節(jié)點(diǎn),對節(jié)點(diǎn)進(jìn)行初始化構(gòu)造

namespace key
{template<class K>struct BSTreeNode{typedef BSTreeNode<K> Node;BSTreeNode(const K& key):left(nullptr), right(nullptr),_key(key){}Node* left;Node* right;K _key;};template<class K>class BSTree{public:bool Insert(const K& key){Node* root = new Node(key);if (_root == nullptr){_root = root;return true;}Node* parent = nullptr;Node* cur = _root;while (cur){if (cur->_key > root->_key){parent = cur;cur = cur->left;}else if (cur->_key < root->_key){parent = cur;cur = cur->right;}else{return false;}}if (parent->_key < root->_key)parent->right = root;elseparent->left = root;return true;}
}

代碼圖解:
在這里插入圖片描述

三、二叉搜索樹的查找

查找非常簡單按照流程找就行了

typedef BSTreeNode<K> Node;
bool Find(const K& key)
{Node* cur = _root;while (cur){if (cur->_key < key){cur = cur->right;}else if (cur->_key > key){cur = cur->left;}else{return true;}}return false;
}

四、二叉搜索樹的刪除(最麻煩,情況最多,一一分析)

3.1首先我們按照一般情況下寫,不考慮特殊情況下

bool Erase(const K& key)
{assert(_root);Node* parent = nullptr;Node* cur = _root;while (cur){if (cur->_key > key){parent = cur;cur = cur->left;}else if (cur->_key < key){parent = cur;cur = cur->right;}else{if (cur->left == nullptr){if (parent->left == cur){parent->left = cur->right;}else{parent->right = cur->right;}delete cur;return true;}else if (cur->right == nullptr){if (parent->left == cur){parent->left = cur->left;}else{parent->right = cur->left;}delete cur;return true;}else{Node* pminleft = cur;Node* minleft = cur->right;while (minleft->left){pminleft = minleft;minleft = minleft->left;}cur->_key = minleft -> _key;if (minleft == pminleft->left)pminleft->left = minleft->right;elsepminleft->right = minleft->right;delete minleft;return true;}}}return false;
}

代碼圖解(解釋找到時(shí)候的情況)

4.1.1左為空的情況(與右為空的情況差不多)

在這里插入圖片描述

4.1.2兩邊都不為空的情況下

在這里插入圖片描述

4.1其次我們考慮極端情況,如果剛好是整體樹的根要刪除

在這里插入圖片描述
調(diào)整代碼如下

				if (cur->left == nullptr){if (cur == _root){_root = cur->right;}else{if (parent->left == cur){parent->left = cur->right;}else{parent->right = cur->right;}}delete cur;return true;}else if (cur->right == nullptr){if (cur == _root){_root = cur->left;}else{if (parent->left == cur){parent->left = cur->left;}else{parent->right = cur->left;}}delete cur;return true;
}

五、二叉搜索樹的中序遍歷

這里我們用了一個(gè)小技巧,就是通過類里面的函數(shù)調(diào)用類里面的私有成員

//中序遍歷
void _Inorder()
{Inorder(_root);
}
private://中序遍歷void Inorder(Node* root){if (root == nullptr)return;Inorder(root->left);cout << root->_key << ' ';Inorder(root->right);}Node* _root = nullptr;

六、二叉搜索樹的拷貝構(gòu)造函數(shù),析構(gòu)函數(shù),賦值操作

6.1 賦值操作(比較簡單)

BSTree<K>& operator=(const BSTree& root)
{swap(_root, root->_root);return *this;
}

6.2拷貝構(gòu)造

BSTree(const BSTree<K>& t)
{_root = Copy(t._root);
}
Node* Copy(Node* root)
{if (root == nullptr)return nullptr;Node* newroot = new Node(root->_key);newroot->left = Copy(root->left);newroot->right = Copy(root->right);return newroot;
}

6.3析構(gòu)函數(shù)

~BSTree()
{Distroy(_root);
}
void Distroy(Node* root)
{if (root == nullptr)return;Distroy(root->left);Distroy(root->right);delete root;
}

七、全部源碼展現(xiàn)(遞歸玩法的代碼也傳進(jìn)來了,下次講解)

#pragma once
#include<iostream>
#include<assert.h>
#include<algorithm>
using namespace std;namespace key
{template<class K>struct BSTreeNode{typedef BSTreeNode<K> Node;BSTreeNode(const K& key):left(nullptr), right(nullptr),_key(key){}Node* left;Node* right;K _key;};template<class K>class BSTree{public://查BSTree() = default;//自動生成默認(rèn)構(gòu)造~BSTree(){Distroy(_root);}BSTree(const BSTree<K>& t){_root = Copy(t._root);}BSTree<K>& operator=(const BSTree& root){swap(_root, root->_root);return *this;}typedef BSTreeNode<K> Node;bool Find(const K& key){Node* cur = _root;while (cur){if (cur->_key < key){cur = cur->right;}else if (cur->_key > key){cur = cur->left;}else{return true;}}return false;}//增bool Insert(const K& key){Node* root = new Node(key);if (_root == nullptr){_root = root;return true;}Node* parent = nullptr;Node* cur = _root;while (cur){if (cur->_key > root->_key){parent = cur;cur = cur->left;}else if (cur->_key < root->_key){parent = cur;cur = cur->right;}else{return false;}}if (parent->_key < root->_key)parent->right = root;elseparent->left = root;return true;}//刪bool Erase(const K& key){assert(_root);Node* parent = nullptr;Node* cur = _root;while (cur){if (cur->_key > key){parent = cur;cur = cur->left;}else if (cur->_key < key){parent = cur;cur = cur->right;}else{if (cur->left == nullptr){if (cur == _root){_root = cur->right;}else{if (parent->left == cur){parent->left = cur->right;}else{parent->right = cur->right;}}delete cur;return true;}else if (cur->right == nullptr){if (cur == _root){_root = cur->left;}else{if (parent->left == cur){parent->left = cur->left;}else{parent->right = cur->left;}}delete cur;return true;}else{Node* pminleft = cur;Node* minleft = cur->right;while (minleft->left){pminleft = minleft;minleft = minleft->left;}cur->_key = minleft -> _key;if (minleft == pminleft->left)pminleft->left = minleft->right;elsepminleft->right = minleft->right;delete minleft;return true;}}}return false;}/		//遞歸玩法//增bool _InsertR(const K& key){_Insert(_root,key);}bool _EraseR(const K& key){_Erase(_root, key);}bool _FindR(const K& key){_Find(_root,key);}void Distroy(Node* root){if (root == nullptr)return;Distroy(root->left);Distroy(root->right);delete root;}//中序遍歷void _Inorder(){Inorder(_root);}private://中序遍歷void Inorder(Node* root){if (root == nullptr)return;Inorder(root->left);cout << root->_key << ' ';Inorder(root->right);}bool _Insert(Node*& root,const K& key){if (root == nullptr){Node* newroot = new Node(key);root = newroot;return true;}if (root->_key > key){_Insert(root->left, key);}else if (root->_key < key){_Insert(root->right, key);}elsereturn false;}Node& _Find(Node*& root, const K& key){if (root == nullptr)return nullptr;if (root->_key > key){_Find(root->left);}else if (root->_key < key){_Find(root->right);}else{return root;}}Node* Copy(Node* root){if (root == nullptr)return nullptr;Node* newroot = new Node(root->_key);newroot->left = Copy(root->left);newroot->right = Copy(root->right);return newroot;}bool _Erase(Node*& root, const K& key){if (root == nullptr)return false;if (root->_key > key){return _Erase(root->left,key);}else if(root->_key < key){return _Erase(root->right ,key);}else{Node* minright = root->right;while (minright->left)minright = minright->left;swap(root->_key,minright->_key);minright->right = minright->right;delete minright;return true;}}Node* _root = nullptr;};
}

在這里插入圖片描述

http://www.risenshineclean.com/news/2123.html

相關(guān)文章:

  • 潘家園網(wǎng)站建設(shè)公司亞馬遜查關(guān)鍵詞排名工具
  • 桂林駿程網(wǎng)站建設(shè)seo優(yōu)化流程
  • 哪個(gè)網(wǎng)站財(cái)經(jīng)做的最好寧波seo資源
  • 移動網(wǎng)站開發(fā)百度百科常州seo收費(fèi)
  • 2017做網(wǎng)站賺錢短視頻平臺推廣方案
  • 重慶seo網(wǎng)站建設(shè)百度站長鏈接提交
  • 手機(jī)有軟件做ppt下載網(wǎng)站王通seo教程
  • 國內(nèi)做日化官方網(wǎng)站怎么推廣軟件
  • 網(wǎng)站開發(fā)自學(xué)還是培訓(xùn)市場營銷計(jì)劃
  • 網(wǎng)站開發(fā)會什么做網(wǎng)絡(luò)營銷推廣
  • sfda的網(wǎng)站的建設(shè)特點(diǎn)免費(fèi)推廣的網(wǎng)站平臺
  • 個(gè)人網(wǎng)站整站源碼下載阜新網(wǎng)絡(luò)推廣
  • 網(wǎng)站制作與維護(hù)公司seo營銷名詞解釋
  • 哪個(gè)網(wǎng)站做演唱會門票網(wǎng)絡(luò)推廣是做什么工作
  • 如何將項(xiàng)目發(fā)布到網(wǎng)上優(yōu)化關(guān)鍵詞首頁排行榜
  • 動態(tài)網(wǎng)站沒有數(shù)據(jù)庫怎么做百度推廣代運(yùn)營公司
  • 做日本暖暖小視頻網(wǎng)站seo服務(wù)內(nèi)容
  • 《網(wǎng)頁設(shè)計(jì)與網(wǎng)站建設(shè)》大作業(yè)要求關(guān)鍵詞愛站網(wǎng)關(guān)鍵詞挖掘工具
  • 想建立什么網(wǎng)站嗎關(guān)鍵詞調(diào)詞平臺哪個(gè)好
  • 網(wǎng)站做二級站全網(wǎng)網(wǎng)絡(luò)營銷
  • 織夢 網(wǎng)站根目錄谷歌瀏覽器下載
  • 如何做網(wǎng)站走查一站式海外推廣平臺
  • 外貿(mào)網(wǎng)站建設(shè)推廣公司百度 營銷推廣怎么做
  • 做網(wǎng)站運(yùn)營這工作怎么樣注冊域名
  • 一搜同志網(wǎng)站建設(shè)電話百度登錄個(gè)人中心
  • wordpress vip 插件網(wǎng)站seo推廣seo教程
  • 深圳疫情最新消息今天seo指搜索引擎
  • 西安做網(wǎng)站公司網(wǎng)絡(luò)優(yōu)化師是什么工作
  • 安徽六安瓜片是什么茶百家號seo怎么做
  • 企業(yè)商城建站最新小組排名