mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-24 23:50:45 +08:00
Cite demo-source regions from the remaining A-class snippets (batch 2) (#2035)
Migrate init_array, hash_map_operations, hash_map_traversal, queue_operations, deque_operations and insert_remove_node: zh and ru demo sources gain region markers and the snippets' comments, en, ja and ko are regenerated from reviewed translations, zh-hant via OpenCC. 70 blocks become region references; builtin_hash and five blocks without reviewed translations stay literal. The Java, Kotlin and Rust deque demos follow the book's order, and a few demo comments and typos are aligned with the snippets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
849b6a95b9
commit
eeb8a3b790
@@ -8,38 +8,54 @@
|
||||
|
||||
/* Driver Code */
|
||||
int main() {
|
||||
// [region]{init_deque}
|
||||
/* 初始化双向队列 */
|
||||
deque<int> deque;
|
||||
// [endregion]{init_deque}
|
||||
|
||||
// [region]{push}
|
||||
/* 元素入队 */
|
||||
deque.push_back(2);
|
||||
deque.push_back(2); // 添加至队尾
|
||||
deque.push_back(5);
|
||||
deque.push_back(4);
|
||||
deque.push_front(3);
|
||||
deque.push_front(3); // 添加至队首
|
||||
deque.push_front(1);
|
||||
// [endregion]{push}
|
||||
cout << "双向队列 deque = ";
|
||||
printDeque(deque);
|
||||
|
||||
// [region]{peek_first}
|
||||
/* 访问元素 */
|
||||
int front = deque.front();
|
||||
int front = deque.front(); // 队首元素
|
||||
// [endregion]{peek_first}
|
||||
cout << "队首元素 front = " << front << endl;
|
||||
int back = deque.back();
|
||||
// [region]{peek_last}
|
||||
int back = deque.back(); // 队尾元素
|
||||
// [endregion]{peek_last}
|
||||
cout << "队尾元素 back = " << back << endl;
|
||||
|
||||
// [region]{pop_first}
|
||||
/* 元素出队 */
|
||||
deque.pop_front();
|
||||
deque.pop_front(); // 队首元素出队
|
||||
// [endregion]{pop_first}
|
||||
cout << "队首出队元素 popFront = " << front << ",队首出队后 deque = ";
|
||||
printDeque(deque);
|
||||
deque.pop_back();
|
||||
// [region]{pop_last}
|
||||
deque.pop_back(); // 队尾元素出队
|
||||
// [endregion]{pop_last}
|
||||
cout << "队尾出队元素 popLast = " << back << ",队尾出队后 deque = ";
|
||||
printDeque(deque);
|
||||
|
||||
// [region]{size}
|
||||
/* 获取双向队列的长度 */
|
||||
int size = deque.size();
|
||||
// [endregion]{size}
|
||||
cout << "双向队列长度 size = " << size << endl;
|
||||
|
||||
// [region]{is_empty}
|
||||
/* 判断双向队列是否为空 */
|
||||
bool empty = deque.empty();
|
||||
// [endregion]{is_empty}
|
||||
cout << "双向队列是否为空 = " << empty << endl;
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user