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
Maplewing
December 06, 2013
Programming
0
140
師大資工系ACM-ICPC讀書會:肆、鏈結串列與二元樹
師大資工系ACM-ICPC讀書會:肆、鏈結串列與二元樹
Maplewing
December 06, 2013
Tweet
Share
More Decks by Maplewing
See All by Maplewing
資訊實務應用讀書會 第七堂課:jQuery
sinmaplewing
0
2k
師大資工系ACM-ICPC讀書會:參、堆疊與佇列
sinmaplewing
0
220
師大資工系ACM-ICPC讀書會:貳、排序搜尋與數學基礎
sinmaplewing
0
190
資訊實務應用讀書會 第六堂課:Basic CSS
sinmaplewing
0
1.7k
師大資工系ACM-ICPC讀書會:壹、字串處理與大數運算
sinmaplewing
0
130
師大資工系ACM-ICPC讀書會:零、比賽介紹、解題系統介紹
sinmaplewing
0
210
資訊實務應用讀書會 第四堂課(支線):Linux
sinmaplewing
0
1.9k
資訊實務應用讀書會 第一堂課:Basic HTML
sinmaplewing
1
2.1k
Other Decks in Programming
See All in Programming
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
420
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 2
philipschwarz
PRO
0
120
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
39
26k
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
200
ゆくKotlin くるRust
exoego
1
170
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
140
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
240
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
140
DevFest Android in Korea 2025 - 개발자 커뮤니티를 통해 얻는 가치
wisemuji
0
180
Denoのセキュリティに関する仕組みの紹介 (toranoana.deno #23)
uki00a
0
180
AIエージェントの設計で注意するべきポイント6選
har1101
6
2.6k
Findy AI+の開発、運用におけるMCP活用事例
starfish719
0
1.8k
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Prompt Engineering for Job Search
mfonobong
0
130
Build your cross-platform service in a week with App Engine
jlugia
234
18k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
76
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
How STYLIGHT went responsive
nonsquared
100
6k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
99
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
61
46k
The Curious Case for Waylosing
cassininazir
0
200
Everyday Curiosity
cassininazir
0
110
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