Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
師大資工系ACM-ICPC讀書會:肆、鏈結串列與二元樹
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Maplewing
December 06, 2013
Programming
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
師大資工系ACM-ICPC讀書會:肆、鏈結串列與二元樹
師大資工系ACM-ICPC讀書會:肆、鏈結串列與二元樹
Maplewing
December 06, 2013
More Decks by Maplewing
See All by Maplewing
資訊實務應用讀書會 第七堂課:jQuery
sinmaplewing
0
2.1k
師大資工系ACM-ICPC讀書會:參、堆疊與佇列
sinmaplewing
0
260
師大資工系ACM-ICPC讀書會:貳、排序搜尋與數學基礎
sinmaplewing
0
210
資訊實務應用讀書會 第六堂課:Basic CSS
sinmaplewing
0
1.8k
師大資工系ACM-ICPC讀書會:壹、字串處理與大數運算
sinmaplewing
0
160
師大資工系ACM-ICPC讀書會:零、比賽介紹、解題系統介紹
sinmaplewing
0
250
資訊實務應用讀書會 第四堂課(支線):Linux
sinmaplewing
0
1.9k
資訊實務應用讀書會 第一堂課:Basic HTML
sinmaplewing
1
2.2k
Other Decks in Programming
See All in Programming
Deep dive into the select statement (GopherCon UK)
jespino
0
170
高専キャリア LT 発表内容
crysta1221
6
5.6k
業務時間外もAIに働いてもらう話
colorful12
3
10k
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
210
PyO3 で既存 Python 評価器を Rust core 化する ー wasm-bindgen でブラウザにも配るための設計
kdash
1
540
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
2
2.3k
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
55
36k
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
2
500
不幸な GC
chencmd
0
890
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.1k
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
3
510
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
560
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
810
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
370
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Amusing Abliteration
ianozsvald
1
290
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Bash Introduction
62gerente
615
220k
Transcript
肆、鏈結串列與二元樹 師大資工系 灆洢 取自於<提升程式設計的邏輯思考力> 6.2 & 6.3
鏈結串列
struct node{ int value; node *next; }; 單向鏈結串列 Singly Linked
List 22 12 32
插入新節點 22 12 32 5 node node.next newnode newnode.next =
node.next; node.next = newnode;
刪除節點 22 12 32 node node.next node.next.next node *delnode =
node.next; node.next = node.next.next; delete delnode;
struct node{ int value; node *prev, *next; }; 雙向鏈結串列 Doubly
Linked List 22 12 32
• List containers are implemented as doubly-linked lists. C++ STL:
list
•127 •101 •133 •10152 •673 •442 作業 •11111 •11234 •540
•10050
二元樹
• 任兩點之間都相通,並且沒有環的圖。 • 來源:演算法筆記 樹 Tree
二元樹 Binary Tree
• 陣列 • 以0為root • 往編號n之左子樹:2*(n+1) - 1 • 往編號n之右子樹:2*(n+1)
• 往父節點:floor((n-1)/2) • 鏈結串列 • struct node { int data; node *left, *right; }; 儲存方式
需要用queue 廣度優先搜尋 BFS: Breadth-first search
深度優先搜尋 DFS: Depth-first search 需要用recursion或stack
樹的走訪:前序、中序、後序
function Preorder(node){ if(!node.left && !node.right){ print(node.value); return; } print(node.value); Preorder(node.left);
Preorder(node.right); } Ans: F,B,A,D,C,E,G,I,H 前序
function Inorder(node){ if(!node.left && !node.right){ print(node.value); return; } Preorder(node.left); print(node.value);
Preorder(node.right); } Ans: ABCDEFGHI 中序
function Postorder(node){ if(!node.left && !node.right){ print(node.value); return; } Preorder(node.left); Preorder(node.right);
print(node.value); } Ans: ACEDBHIGF 後序
• 給予前序與中序,如何找出後序? • 前:DBACEGF 中:ABCDEFG • 後:ACBFGED 問題:二元樹重建
作業 •112 •548 •297 •712 •699 •327 •839 •10562
謝謝聆聽 資料取自於<提升程式設計的邏輯思考力> 6.2 & 6.3