国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

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

中山自助建站系統(tǒng)外貿(mào)網(wǎng)站建設(shè)公司

中山自助建站系統(tǒng),外貿(mào)網(wǎng)站建設(shè)公司,哪些網(wǎng)站可以做微信推送,做網(wǎng)站一般幾個(gè)人一 std::list 介紹 list 是 c 中的序列式容器,其實(shí)現(xiàn)是雙向鏈表,每個(gè)元素都有兩個(gè)指針,分別指向前一個(gè)節(jié)點(diǎn)與后一個(gè)節(jié)點(diǎn) 鏈表與數(shù)組都是計(jì)算機(jī)常用的內(nèi)存數(shù)據(jù)結(jié)構(gòu),與數(shù)組連續(xù)內(nèi)存空間不一樣的地方在于,鏈表的空間是不…

一? std::list 介紹

? ? ? ?list 是 c++ 中的序列式容器,其實(shí)現(xiàn)是雙向鏈表,每個(gè)元素都有兩個(gè)指針,分別指向前一個(gè)節(jié)點(diǎn)與后一個(gè)節(jié)點(diǎn)

? ? ? 鏈表與數(shù)組都是計(jì)算機(jī)常用的內(nèi)存數(shù)據(jù)結(jié)構(gòu),與數(shù)組連續(xù)內(nèi)存空間不一樣的地方在于,鏈表的空間是不連續(xù)的,鏈表是將一塊塊不連續(xù)的內(nèi)存串聯(lián)起來(lái)使用。

? ? 正是由于鏈表的內(nèi)存不連續(xù)這一特點(diǎn),所以不能像數(shù)組一樣,可以根據(jù)位置隨機(jī)的訪問(wèn)每個(gè)元素,而鏈表我們壓根不知道每個(gè)元素的實(shí)際位置到底在哪塊內(nèi)存區(qū)域。

? ? ?查找某個(gè)元素需要遍歷整個(gè)鏈表,直到找到目標(biāo)元素位置,時(shí)間復(fù)雜度是 O(n);

? ? 在鏈表中插入一個(gè)元素與刪除一個(gè)元素的時(shí)間復(fù)雜度是 O(1);

二? ?c++ 中 stl 鏈表結(jié)構(gòu)

1. list 結(jié)構(gòu)

? ?list? 結(jié)構(gòu)?(借用侯捷老師的一張圖片來(lái)):

??

? 由上面的結(jié)構(gòu)上可以看出,list 是一個(gè)循環(huán)鏈表,鏈表的尾端是一個(gè)空節(jié)點(diǎn),不存儲(chǔ)任何數(shù)據(jù)。

三? ?c++ 中 stl 鏈表使用

?1? 構(gòu)造函數(shù)

構(gòu)造函數(shù)說(shuō)明
list()空構(gòu)造函數(shù)
list(?size_type count, const?T&?value)初始化一個(gè)元素?cái)?shù)量為 count 個(gè)的 value 元素
list(?std::initializer_list<T>?init)利用列表初始化 list
list(?InputIt first, InputIt last)利用迭代器的起始于終止位置初始化 list

?2? ?容器修改

函數(shù)說(shuō)明
clear()?清空所有元素
insert在指定位置插入元素
emplace在指定位置插入元素, 可以通過(guò)直接傳入元素類的構(gòu)造參數(shù)實(shí)現(xiàn)原地構(gòu)造
erase移除指定元素
push_backappend 元素到鏈表的尾部
pop_back將鏈表尾部元素彈出
push_frontappend 元素到鏈表的頭部
pop_front將鏈表頭部元素彈出
emplace_backappend 元素到鏈表的尾部, 可以通過(guò)直接傳入元素類的構(gòu)造參數(shù)實(shí)現(xiàn)原地構(gòu)造
emplace_frontappend 元素到鏈表的頭部, 可以通過(guò)直接傳入元素類的構(gòu)造參數(shù)實(shí)現(xiàn)原地構(gòu)造

?3? 容器訪問(wèn)

函數(shù)說(shuō)明
begin返回頭部元素的迭代器
end返回尾部元素的迭代器
rbegin返回尾部元素的迭代器
rend返回頭部元素的迭代器
front返回頭部元素的引用
back返回尾部元素的引用

4? 容器容量

函數(shù)說(shuō)明
empty判斷 list是否為空
size返回 list 存儲(chǔ)元素的個(gè)數(shù)
#include<iostream>
#include<list>int main()
{// 1. 構(gòu)造函數(shù)std::list<int> list;auto iter = list.begin();std::cout << *iter << "--- " << std::endl;;// 2. 容器修改list.push_back(1);list.push_back(2);list.push_back(3);list.push_back(4);list.push_back(5);list.push_front(11);list.push_front(22);list.pop_back();list.pop_front();list.insert(list.begin(), 666);// 3. 容器訪問(wèn)for(auto iter = list.begin(); iter != list.end();iter++){std::cout << *iter << " "; // 666 11 1 2 3 4}std::cout << "" << std::endl;for(auto iter = list.rbegin(); iter != list.rend();iter++){std::cout << *iter << " "; // 4 3 2 1 11 666}std::cout << "" << std::endl;std::cout << "first: " << list.front() << ", finish: " << list.back() << std::endl; // first: 666, finish: 4// 4. 容器容量std::cout << "empyt: " << list.empty() << std::endl; // 0std::cout << "size: "<< list.size() << std::endl; // 6list.clear();std::cout << "empyt: " << list.empty() << std::endl; // 1std::cout << "size: "<< list.size() << std::endl; // 0return 0;
}

四? 簡(jiǎn)單實(shí)現(xiàn)

??

// my_list.h#include<memory>
#include<iostream>template<typename T>
struct _List_Node
{typedef _List_Node node;_List_Node(){prev = nullptr;next = nullptr;}_List_Node(T& da):data(da){prev = nullptr;next = nullptr;}_List_Node(T&& da):data(da){prev = nullptr;next = nullptr;}~_List_Node(){prev = nullptr;next = nullptr;}node* prev;node* next;T data;
};template<typename T>
struct _List_Iterator
{typedef T valueType;typedef T& refrence;typedef T* pointer;typedef  _List_Node<T> node;_List_Iterator(node* val):data(val){}_List_Iterator& operator++(){this->data = this->data->next;return *this;}_List_Iterator operator++(int){_List_Iterator tmp = *this;++(*this);return tmp;}_List_Iterator& operator--(){this->data = this->data->prev;return *this;}_List_Iterator operator--(int){_List_Iterator tmp = *this;--(*this);return tmp;}T& operator*(){return this->data->data;}bool operator != (_List_Iterator& other){return this->data != other->data;}bool operator == (_List_Iterator& other){return this->data == other.data;}bool operator != (_List_Iterator&& other){return this->data != other.data;}bool operator == (_List_Iterator&& other){return this->data == other.data;}node*  data;
};template<typename T>
class my_list
{typedef  _List_Node<T>  node;typedef  _List_Iterator<T> iterator;
public:my_list():count(0){next_curr = new node;pre_curr = next_curr;finish = new node;next_curr->next = finish;finish->next = next_curr;pre_curr->prev = finish;finish->prev = pre_curr;}~my_list(){node* tmp = pre_curr;while (tmp != nullptr) {node* tt = tmp->next;delete tmp;tmp = tt;}}void push_back(T& val){std::cout << "count: " << count << std::endl;if(count == 0)next_curr->data = val;else {node* tmp = new node(val);tmp->next = next_curr->next;tmp->next->prev = tmp;next_curr->next = tmp;tmp->prev = next_curr;next_curr = next_curr->next;}count++;}void push_back(T&& val){push_back(val);}void push_front(T& val){if(count == 0)pre_curr->data = val;else {node* tmp = new node(val);tmp->prev = pre_curr->prev;pre_curr->prev->next = tmp;tmp->next = pre_curr;pre_curr->prev = tmp;pre_curr = pre_curr->prev;}count++;}void push_front(T&& val){push_front(val);}void pop_back(){if(count == 0){return;} else{node* tmp = next_curr;next_curr->prev->next = next_curr->next;next_curr->next->prev = next_curr->prev;next_curr = next_curr->prev;delete tmp;count--;}}void pop_front(){if(count == 0){return;} else{node* tmp = pre_curr;finish->next = pre_curr->next;pre_curr->next->prev = finish;pre_curr = pre_curr->next;delete tmp;count--;}}int size(){return count;}iterator begin(){return iterator(pre_curr);}iterator end(){return iterator(finish);}iterator rbegin(){return iterator(finish->prev);}iterator rend(){return iterator(pre_curr->prev);}void insert(iterator pos, T& val){node* tmp = new node(val);pos.data->prev->next = tmp;tmp->prev = pos.data->prev;tmp->next = pos.data;pos.data->prev = tmp;if(pos.data == pre_curr){pre_curr = pre_curr->prev;}else if(pos.data == next_curr){next_curr = next_curr->next;}count++;}void insert(iterator pos, T&& val){insert(pos, val);}template<typename ... Args>void emplace(iterator pos, Args... args){node* tmp = new node(std::forward<Args>(args)...);pos.data->prev->next = tmp;tmp->prev = pos.data->prev->next;tmp->next = pos.data;pos.data->prev = tmp;count++;}void erase(iterator pos){node* tmp = pos.data;tmp->prev = tmp->next;delete tmp;count--;}void clear(){while (pre_curr->next != finish) {pop_back();}count = 0;}T& front(){return pre_curr->data;}T& back(){return next_curr->data;}bool empty(){return count == 0;}public:node* next_curr = nullptr;node* pre_curr = nullptr;node* finish = nullptr;int count;
};// main.cpp
#include<iostream>
#include<my_list.h>int main()
{// 1. 構(gòu)造函數(shù)my_list<int> list;// 2. 容器修改list.push_back(1);list.push_back(2);list.push_back(3);list.push_back(4);list.push_back(5);list.push_front(11);list.push_front(22);// 22 11 1 2 3 4 5list.pop_back();list.pop_front();list.insert(list.begin(), 666);// 3. 容器訪問(wèn)for(auto iter = list.begin(); iter != list.end();iter++){std::cout << *iter << " "; // 666 11 1 2 3 4}std::cout << "" << std::endl;for(auto iter = list.rbegin(); iter != list.rend();iter--){std::cout << *iter << " "; // 4 3 2 1 11 666}std::cout << "" << std::endl;std::cout << "first: " << list.front() << ", finish: " << list.back() << std::endl; // first: 666, finish: 4// 3. 容器容量std::cout << "empty: " << list.empty() << std::endl; // 0std::cout << "size: "<< list.size() << std::endl; // 6list.clear();std::cout << "empyt: " << list.empty() << std::endl; // 1std::cout << "size: "<< list.size() << std::endl; // 0return 0;
}

http://m.aloenet.com.cn/news/34996.html

相關(guān)文章:

  • 論基層門戶網(wǎng)站的建設(shè)微信軟文范例100字
  • 免費(fèi)編程網(wǎng)課seo在線優(yōu)化技術(shù)
  • 上海商城網(wǎng)站建設(shè)搜狐綜合小時(shí)報(bào)2022113011
  • 免費(fèi)只做網(wǎng)站2024百度下載
  • 德州市建設(shè)局網(wǎng)站合肥網(wǎng)絡(luò)seo
  • 上海建網(wǎng)站手機(jī)app福州百度首頁(yè)優(yōu)化
  • 離石做網(wǎng)站的網(wǎng)絡(luò)公司fba歐美專線
  • 藍(lán)色風(fēng)格網(wǎng)站外鏈發(fā)布軟件
  • 網(wǎng)站軟文標(biāo)題seo查詢 站長(zhǎng)之家
  • 有沒(méi)有做網(wǎng)站的教程網(wǎng)站收錄查詢代碼
  • 深圳網(wǎng)站建設(shè)代理商哪家網(wǎng)絡(luò)推廣好
  • 外貿(mào)購(gòu)物網(wǎng)站短視頻如何引流與推廣
  • 做視頻網(wǎng)站怎么掙錢有沒(méi)有免費(fèi)的推廣網(wǎng)站
  • 晉江網(wǎng)站建設(shè)公司網(wǎng)絡(luò)營(yíng)銷推廣方案怎么寫(xiě)
  • wordpress分詞seo項(xiàng)目培訓(xùn)
  • 百度競(jìng)價(jià)點(diǎn)擊軟件網(wǎng)站seo整站優(yōu)化
  • 微信輔助網(wǎng)站制作論壇排名
  • 免費(fèi)的logo設(shè)計(jì)網(wǎng)站推廣運(yùn)營(yíng)怎么做
  • 微網(wǎng)站開(kāi)發(fā)北京關(guān)鍵詞優(yōu)化一年的收費(fèi)標(biāo)準(zhǔn)
  • 東莞網(wǎng)站開(kāi)發(fā)站長(zhǎng)之家網(wǎng)站排行榜
  • 濰坊網(wǎng)站建設(shè)(首選聚搜網(wǎng)絡(luò))cps推廣平臺(tái)有哪些
  • wordpress cdn圖片加速常用的seo查詢工具
  • 網(wǎng)站視頻建設(shè)常德論壇網(wǎng)站
  • 購(gòu)物網(wǎng)站最重要的功能專業(yè)網(wǎng)頁(yè)設(shè)計(jì)和網(wǎng)站制作公司
  • 網(wǎng)站查詢域名訪問(wèn)網(wǎng)絡(luò)營(yíng)銷渠道建設(shè)方案
  • 公司的網(wǎng)站建設(shè)一般需要多少費(fèi)用sem優(yōu)化怎么做
  • 中英文網(wǎng)站asp怎么做seo推廣軟件費(fèi)用
  • 找人做網(wǎng)站應(yīng)該注意什么福州seo兼職
  • 打開(kāi)鏈接的網(wǎng)站網(wǎng)絡(luò)營(yíng)銷計(jì)劃的七個(gè)步驟
  • 自制網(wǎng)站的動(dòng)態(tài)圖怎么做創(chuàng)意廣告