LIFO(last in first out, ) 1 FIFO(first in first out, ) 2 2 PUSH POP : 1

Similar documents
( ) ( ) 30 ( ) 27 [1] p LIFO(last in first out, ) (push) (pup) 1

memo

Microsoft PowerPoint - kougi10.ppt

untitled

memo

O(N) ( ) log 2 N

第2回

Microsoft Word - no206.docx

PowerPoint プレゼンテーション

二分木の実装

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

PowerPoint プレゼンテーション

Microsoft Word - 12

Taro-2分探索木Ⅰ(公開版).jtd

第2回

r07.dvi

Microsoft Word - 13

ohp07.dvi

Taro-2分探索木Ⅱ(公開版).jtd

# let st1 = {name = "Taro Yamada"; id = };; val st1 : student = {name="taro Yamada"; id=123456} { 1 = 1 ;...; n = n } # let string_of_student {n

Taro-リストⅢ(公開版).jtd

untitled

alg2015-6r3.ppt

r03.dvi

untitled

L eaf

ohp03.dvi

ohp11.dvi

r11.dvi

PowerPoint Presentation

アルゴリズムとデータ構造1

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

main

1.

C言語によるアルゴリズムとデータ構造

Microsoft Word - 第5回 基本データ構造2(連結リスト).doc

Microsoft Word - NonGenTree.doc

fp.gby

Taro-リストⅠ(公開版).jtd

Microsoft PowerPoint - kougi11.ppt

ALG ppt

平成 31 年度 筑波大学大学院博士課程 システム情報工学研究科 コンピュータサイエンス専攻 博士前期課程 ( 一般入学試験 8 月期 ) 試験問題基礎科目 ( 数学, 情報基礎 ) Mathematics/Fundamentals of Computer Science [ 注意事項 ][Inst

始めに, 最下位共通先祖を求めるための関数 LcaDFS( int v ) の処理を記述する. この関数は値を返さない再帰的な void 関数で, 点 v を根とする木 T の部分木を深さ優先探索する. 整数の引数 v は, 木 T の点を示す点番号で, 配列 NodeSpace[ ] へのカーソル

プログラミングI第10回

Microsoft PowerPoint - 6.pptx

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

untitled

‚æ4›ñ

PowerPoint Presentation




プログラミング及び演習 第1回 講義概容・実行制御

橡Pro PDF

Parametric Polymorphism

program.dvi

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

double float

mnal_HDR4ex_5ex.pdf

Microsoft PowerPoint - 05.pptx

2004

TC316_A5_2面_web用PDF台紙.indd

untitled

yacc.dvi

memo

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

Microsoft PowerPoint - 06.pptx

org/ghc/ Windows Linux RPM 3.2 GHCi GHC gcc javac ghc GHCi(ghci) GHCi Prelude> GHCi :load file :l file :also file :a file :reload :r :type expr :t exp

ALG2012-A.ppt

文字数は1~6なので 同じ本数の枝を持つパスで生成される呪文の長さは最大で6 倍の差がある 例えば 上図のようなケースを考える 1サイクル終了した時点では スター節点のところに最強呪文として aaaaaac が求まる しかしながら サイクルを繰り返していくと やがてスター節点のところに aaaaaa

. 61 5,000 5, ,

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

第3回 配列とリスト

新・明解C言語で学ぶアルゴリズムとデータ構造



好きですまえばし

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

Microsoft Word - no205.docx

I void* School of Information Science, Japan Advanced Institute of Science and Technology

t 2 2 t 2 t F ( ) p- 2 2 F 2 G F ( ) 2 2 F 2 G F ( ) 2 2 2

2018年度「プログラミング言語」配布資料 (12)

920P-1



広報しもつけp01ol

ONPRESS190


本文(B5×40)0614三校責了.indd


C C UNIX C ( ) 4 1 HTML 1

cpp1.dvi

Microsoft Word - Cプログラミング演習(12)

6-1

73 p p.152

122011pp

Microsoft Word - 映画『東京裁判』を観て.doc

Transcription:

2007 7 17 2 1 1.1 LIFO(last in first out, ) 1 FIFO(first in first out, ) 2 2 PUSH POP 2 2 5 5 5 1: 1

2 データの追加 データの取り出し 5 2 5 2 5 2: 1.2 [1] pp.199 217 2 (binary tree) 2 2.1 (three: ) ( ) 秋田高専 校長 準学士課程学生 専攻科課程学生 教員 職員 機械 電気情報 物質 環境都市 生産システム 環境システム 人文社会 自然科学 機械 電気情報 物質 環境都市 総務 学生 :! 2

2.2 2.2.1 1 1? 親 ブランチ B D ノード G H I リーフ リーフ リーフ ブランチ ノード ブランチ ルート A レベル0 ブランチ C ノードレベル1 子 E ノード F レベル2 リーフ J レベル リーフ 1: (root: ) (node: ) (leaf: ) (branch: ) (parent) (child) (brother) : B E 2.2.2 2.2. (preorder) 5 a b d g e h i c f j (postorder) 2 2 5 g d b h e i a c f j

(inorder) 5 g d h i e b j f c a 2 a b c d e f g h i j 5: 2.1 2 2 (binary tree) 2 2 2 (postorder) 11 15 20 2 1 7 55 5 7 1 9

2 15 7 11 20 1 7 5 55 9 1 9 : (2 ).2 2,10,2,,12, 7 10 2 10 1 2 10 2 2 10 12 5 7: 2 10 12. 9 5

2 10 12 9 :. 9 2 10 12 7 9 1 9: 2 ( 10) ( 11) ( ) ( 12)

2 10 10 2 9 12 12 12 7 9 1 7 9 1 7 1 10: 9 11: 9 2 12: 9 10.1 2 C! typedef struct node_tag{ int ; struct node_tag *left; struct node_tag *right; }node; 1 node *root_tree=null; tree node (NULL) 7

root_tree NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1: 5 [ 1] 2? 9 52 2 79 2 7 25 75 15 5 1 15 2 72 9 15 15 2 51 9 ( ) ( ) ( ) ( ) [ 2] [ ] 2 9,2,,5,9,5,11,12,1,2, 2 70,7,7,75,77, 2

52 2 7 1 0 5 9 5 5 2 9 1 9 5 2 0 91 99 2 [ ] 2 52,,5 52 2 1 0 7 5 9 20 5 5 72 2 9 9 2 1 2 5 2 0 5 91 99 2 [ 5] 2 [ 1] ( ) [1] pp.199 25 2 2 [ 2] ( ) 2 2 [ ] ( ) 2 5 51 2 7 15 17 2 5 1 70 [ ] 1 2 2 2 0 9

52 2 1 0 7 5 9 5 20 5 5 9 25 1 5 91 99 1: 2 [ 5] 15 2 52 2 5 5 0 15 2 77 90 10 2 57 70 0 9 15: 2 [ ] ( ) 7 2 ( )AM :5 10

A 1: (b tree.h) 1 //============= ============================== 2 typedef struct node tag { int ; struct node tag l e f t ; 5 struct node tag r i g h t ; } node ; 7 //============== ================================= 9 extern node c r e a t n o d e ( int new data ) ; 10 extern void i n s e r t n o d e ( node t node, int new data ) ; 11 extern void d e l e t e n o d e ( node del node, int d e l d a t a ) ; 12 extern void p r i n t t r e e ( node t node, int depth ) ; 1 1 15 extern node r o o t t r e e ; 2: (b tree.c) 1 #include <s t d i o. h> 2 #include <s t d l i b. h> #include b t r e e. h 5 node r o o t t r e e=null; 7 //============== ================================================== node c r e a t n o d e ( int new data ) 9 { 10 node new node ; 11 12 new node=(node ) malloc ( s i z e o f ( node ) ) ; 1 1 new node > = new data ; 15 new node >l e f t = NULL; 1 new node >r i g h t = NULL; 17 1 return new node ; 19 } 20 21 22 //============== ======================================= 2 void i n s e r t n o d e ( node t node, int new data ) 2 { 25 2 i f ( t node==null){ // r o o t ( ) 27 r o o t t r e e = c r e a t n o d e ( new data ) ; 2 return ; 29 } 0 1 i f ( t node > > new data ){ 2 i f ( t node >l e f t == NULL){ t node >l e f t=c r e a t n o d e ( new data ) ; } else { 5 i n s e r t n o d e ( t node >l e f t, new data ) ; } 11

7 } else { i f ( t node >r i g h t == NULL){ 9 t node >r i g h t=c r e a t n o d e ( new data ) ; 0 } else { 1 i n s e r t n o d e ( t node >r i g h t, new data ) ; 2 } } 5 return ; } 7 //============== ====================================== 9 void d e l e t e n o d e ( node del node, int d e l d a t a ) 50 { 51 node parent=null; // 52 node big=null; // 5 node pbig=null; // 5 int f l a g =0; 55 5 // 57 while ( d e l n o d e!=null && del node >!= d e l d a t a ){ 5 i f ( del node > < d e l d a t a ){ 59 parent = d e l n o d e ; 0 d e l n o d e = d e l n o d e > r i g h t ; 1 } else { 2 parent = d e l n o d e ; d e l n o d e = d e l n o d e > l e f t ; } 5 } 7 i f ( d e l n o d e==null){ p r i n t f (! \ n ) ; 9 return ; 70 } 71 72 i f ( del node >l e f t == NULL){ // 7 i f ( parent==null){ // r o o t 7 r o o t t r e e = del node >r i g h t ; 75 } else i f ( parent > > d e l d a t a ){ // 7 parent >l e f t=del node >r i g h t ; 77 } else { // 7 parent >r i g h t=del node >r i g h t ; 79 } 0 f r e e ( d e l n o d e ) ; 1 return ; 2 } i f ( del node >r i g h t == NULL){ // 5 i f ( parent==null){ // r o o t r o o t t r e e = del node >r i g h t ; 7 } else i f ( parent > > d e l d a t a ){ parent >l e f t=del node >l e f t ; 9 } else { // 90 parent >r i g h t=del node >l e f t ; 91 } 92 f r e e ( d e l n o d e ) ; 9 return ; 9 } 95 9 // 97 9 pbig=d e l n o d e ; 12

99 big=del node >l e f t ; 100 101 while ( big >r i g h t!= NULL){ // 102 pbig = big ; 10 big = big >r i g h t ; 10 f l a g = 1 ; 105 } 10 107 del node > = big > ; 10 109 i f ( f l a g == 0){ 110 pbig >l e f t = big >l e f t ; 111 } else { 112 pbig >r i g h t = big >l e f t ; 11 } 11 115 f r e e ( big ) ; 11 117 11 } 119 120 121 //============== ===================================== 122 void p r i n t t r e e ( node t node, int depth ) 12 { 12 int i ; 125 12 i f ( t node==null) return ; 127 12 p r i n t t r e e ( t node >r i g h t, depth +1); 129 10 for ( i =0; i <depth ; i ++) p r i n t f ( ) ; 11 p r i n t f ( %d\n, t node > ) ; 12 1 p r i n t t r e e ( t node >l e f t, depth +1); 1 15 return ; 1 } 1 #include <s t d i o. h> 2 #include b t r e e. h int main ( void ) 5 { 7 i n s e r t n o d e ( r o o t t r e e, 5 ) ; i n s e r t n o d e ( r o o t t r e e, 9 ) ; 9 i n s e r t n o d e ( r o o t t r e e, ) ; 10 i n s e r t n o d e ( r o o t t r e e, ) ; 11 i n s e r t n o d e ( r o o t t r e e, 7 ) ; 12 i n s e r t n o d e ( r o o t t r e e, ) ; 1 i n s e r t n o d e ( r o o t t r e e, 1 0 ) ; 1 i n s e r t n o d e ( r o o t t r e e, 1 2 ) ; 15 i n s e r t n o d e ( r o o t t r e e, 2 ) ; 1 i n s e r t n o d e ( r o o t t r e e, 1 ) ; 17 1 p r i n t f ( \n\n ) ; 19 p r i n t t r e e ( r o o t t r e e, 0 ) ; 20 : (main.c) 1

21 d e l e t e n o d e ( r o o t t r e e, 9 ) ; 22 p r i n t f ( \n\n ) ; 2 p r i n t t r e e ( r o o t t r e e, 0 ) ; 2 return 0 ; 25 } [1], ( ). C 2. ( ), 200. 1