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

當前位置: 首頁 > news >正文

手機高端網(wǎng)站開發(fā)企業(yè)網(wǎng)站設(shè)計與實現(xiàn)論文

手機高端網(wǎng)站開發(fā),企業(yè)網(wǎng)站設(shè)計與實現(xiàn)論文,移動端web網(wǎng)站,nodejs做的網(wǎng)站目錄 棧 棧(stack)的聲明: push(): 將元素推入棧頂 pop(): 彈出棧頂元素 top(): 訪問棧頂元素,但不彈出 empty(): 檢查棧是否為空 size(): 返回棧中元素的數(shù)量 …

目錄

棧(stack)的聲明:

push(): 將元素推入棧頂

pop(): 彈出棧頂元素

top(): 訪問棧頂元素,但不彈出

empty(): 檢查棧是否為空?

size(): 返回棧中元素的數(shù)量?

emplace(): 在棧頂構(gòu)造一個元素?

== 和 !=: 用于比較兩個棧是否相等或不相等

隊列

隊列(queue)的聲明:

push(): 將元素推入隊列尾部

pop(): 從隊列頭部彈出元素

front(): 訪問隊列頭部元素

back(): 訪問隊列尾部元素

empty(): 檢查隊列是否為空

總結(jié)


棧(stack)的聲明:

#include <stack>// 聲明一個整數(shù)類型的棧
std::stack<int> myStack;// 在棧中壓入元素
myStack.push(10);
myStack.push(20);// 彈出棧頂元素
myStack.pop();// 訪問棧頂元素
int topElement = myStack.top();

push(): 將元素推入棧頂

#include <stack>std::stack<int> myStack;myStack.push(10);
myStack.push(20);

pop(): 彈出棧頂元素

myStack.pop();

top(): 訪問棧頂元素,但不彈出

int topElement = myStack.top();

empty(): 檢查棧是否為空?

if (myStack.empty()) {// 棧為空
}

size(): 返回棧中元素的數(shù)量?

size_t stackSize = myStack.size();

emplace(): 在棧頂構(gòu)造一個元素?

myStack.emplace(30);

== 和 !=: 用于比較兩個棧是否相等或不相等

std::stack<int> stackA;
std::stack<int> stackB;// ...if (stackA == stackB) {// 棧A和棧B相等
}if (stackA != stackB) {// 棧A和棧B不相等
}

妙用?

逆波蘭表達式計算: 使用棧來計算逆波蘭表達式。運算符遇到時,彈出棧頂?shù)牟僮鲾?shù)進行計算,并將結(jié)果重新壓入棧。

// 逆波蘭表達式:3 4 + 5 *
std::stack<int> st;
st.push(3);
st.push(4);
st.push(st.top() + 5);  // 3 + 4
st.pop();
int result = st.top() * 5;  // (3 + 4) * 5

括號匹配檢查: 使用棧來檢查表達式中的括號是否匹配。遍歷表達式,遇到左括號壓入棧,遇到右括號時檢查棧頂是否是對應(yīng)的左括號。

std::stack<char> st;
std::string expression = "((a + b) * (c - d))";
for (char c : expression) {if (c == '(') {st.push(c);} else if (c == ')') {if (st.empty() || st.top() != '(') {// 括號不匹配break;}st.pop();}
}
bool isBalanced = st.empty();

函數(shù)調(diào)用堆棧: 編程語言中的函數(shù)調(diào)用使用堆棧來保存局部變量和返回地址。當函數(shù)調(diào)用時,創(chuàng)建一個新的棧幀,函數(shù)執(zhí)行完畢后,將棧幀彈出。

void func1() {int x = 10;// ...
}void func2() {int y = 20;// ...
}int main() {func1();func2();return 0;
}

隊列

隊列(queue)的聲明:

#include <queue>// 聲明一個整數(shù)類型的隊列
std::queue<int> myQueue;// 在隊列尾部插入元素
myQueue.push(30);
myQueue.push(40);// 從隊列頭部彈出元素
myQueue.pop();// 訪問隊列頭部元素
int frontElement = myQueue.front();

push(): 將元素推入隊列尾部

#include <queue>std::queue<int> myQueue;myQueue.push(10);
myQueue.push(20);

pop(): 從隊列頭部彈出元素

myQueue.pop();

front(): 訪問隊列頭部元素

int frontElement = myQueue.front();

back(): 訪問隊列尾部元素

int backElement = myQueue.back();

empty(): 檢查隊列是否為空

if (myQueue.empty()) {// 隊列為空
}

隊列妙用?

廣度優(yōu)先搜索(BFS): 在圖或樹的遍歷中,使用隊列來實現(xiàn)廣度優(yōu)先搜索,確保按照層次遍歷節(jié)點。

void BFS(Node* root) {std::queue<Node*> q;q.push(root);while (!q.empty()) {Node* current = q.front();// 處理當前節(jié)點// ...// 將當前節(jié)點的鄰居節(jié)點入隊for (Node* neighbor : current->neighbors) {q.push(neighbor);}// 出隊q.pop();}
}

任務(wù)調(diào)度: 在操作系統(tǒng)或并發(fā)編程中,使用隊列來管理任務(wù)隊列,確保按照先進先出的原則執(zhí)行任務(wù)。

#include <queue>
#include <thread>
#include <iostream>std::queue<std::function<void()>> taskQueue;
std::mutex taskQueueMutex;void workerThread() {while (true) {std::function<void()> task;{std::lock_guard<std::mutex> lock(taskQueueMutex);if (!taskQueue.empty()) {task = taskQueue.front();taskQueue.pop();}}if (task) {task();} else {// Sleep or yield to avoid busy-waitingstd::this_thread::yield();}}
}

緩存管理: 使用隊列來管理緩存中的數(shù)據(jù),確保最先進入緩存的數(shù)據(jù)最先被替換。?

#include <queue>
#include <iostream>std::queue<int> cache;void addToCache(int data) {cache.push(data);// 如果緩存大小超過限制,移除隊首元素if (cache.size() > MAX_CACHE_SIZE) {cache.pop();}
}

打印任務(wù)隊列: 模擬打印任務(wù)的隊列,確保先提交的打印任務(wù)先得到執(zhí)行。

?

#include <queue>
#include <iostream>std::queue<std::string> printQueue;void submitPrintJob(const std::string& document) {printQueue.push(document);
}void printNextJob() {if (!printQueue.empty()) {std::string document = printQueue.front();std::cout << "Printing: " << document << std::endl;printQueue.pop();}
}

總結(jié)

????????棧(Stack)和隊列(Queue)是兩種基本的數(shù)據(jù)結(jié)構(gòu),分別以后進先出(Last-In-First-Out,LIFO)和先進先出(First-In-First-Out,FIFO)的原則組織數(shù)據(jù)。在面試中,它們常被用于解決各種問題。

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

相關(guān)文章:

  • 做網(wǎng)站 (公司)如何做好平臺推廣
  • 做外貿(mào)怎樣免費登錄外國網(wǎng)站網(wǎng)頁設(shè)計首頁制作
  • 網(wǎng)站數(shù)據(jù)庫連接失敗百度識圖在線識別
  • 做教程的網(wǎng)站內(nèi)容怎么找百度統(tǒng)計收費嗎
  • 汕頭個人建站模板seo排名優(yōu)化技術(shù)
  • 網(wǎng)站制作用的軟件上海網(wǎng)絡(luò)營銷上海網(wǎng)絡(luò)推廣
  • 1688域名網(wǎng)站近三天時政熱點
  • 青島百度seoseo網(wǎng)站地圖
  • wordpress不能啟動怎么解決西安百度快照優(yōu)化
  • 電商網(wǎng)站如何備案google付費推廣
  • 現(xiàn)在網(wǎng)絡(luò)推廣方式衡陽百度seo
  • 宜昌市水利建設(shè)工程協(xié)會網(wǎng)站軟文營銷文章300字
  • b2b是什么網(wǎng)站新網(wǎng)站如何推廣
  • 研學(xué)網(wǎng)站平臺建設(shè)方案市場調(diào)研方法有哪些
  • 電子商務(wù)網(wǎng)站建設(shè)的實訓(xùn)報告網(wǎng)絡(luò)營銷企業(yè)案例分析
  • 網(wǎng)站留言板漏洞百度手機瀏覽器
  • bt網(wǎng)頁游戲網(wǎng)站網(wǎng)絡(luò)平臺營銷
  • 瑞典網(wǎng)站后綴濟南seo網(wǎng)站優(yōu)化公司
  • 網(wǎng)站做擔(dān)保交易網(wǎng)頁設(shè)計首頁制作
  • 常德市做網(wǎng)站的公司百度廣告關(guān)鍵詞價格表
  • 全國物流信息網(wǎng)安徽網(wǎng)站seo公司
  • 成都 網(wǎng)站建設(shè)培訓(xùn)semen
  • 網(wǎng)站建設(shè)試題以及答案鞍山網(wǎng)絡(luò)推廣
  • 藝麟盛世可以做網(wǎng)站推廣嗎鄭州seo優(yōu)化
  • 做配件出口上什么網(wǎng)站搜索引擎優(yōu)化的主要內(nèi)容
  • 網(wǎng)站seo 工具steam交易鏈接怎么獲取
  • 怎么做交易貓釣魚網(wǎng)站短視頻剪輯培訓(xùn)班速成
  • 臨安做網(wǎng)站的公司有哪些搜狗網(wǎng)
  • 用word 做網(wǎng)站seo推廣軟件排名
  • 做電影網(wǎng)站需要官網(wǎng)seo哪家公司好