• 沒有找到結果。

March31,2015 Hsuan-TienLin Stacks,Queues,Deques

N/A
N/A
Protected

Academic year: 2022

Share "March31,2015 Hsuan-TienLin Stacks,Queues,Deques"

Copied!
4
0
0

加載中.... (立即查看全文)

全文

(1)

Stacks, Queues, Deques

Hsuan-Tien Lin

Dept. of CSIE, NTU

March 31, 2015

H.-T. Lin (NTU CSIE) Stacks, Queues, Deques 03/31/2015 0 / 3

(2)

Stacks

Stack

object: a container that holds some elements

action: [constant-time] push (to the top), pop (from the top)

last-in-first-out (LIFO): 擠電梯 , 洗盤子

very restricted data structure, but important for computers

—will discuss some cases later

H.-T. Lin (NTU CSIE) Stacks, Queues, Deques 03/31/2015 1 / 3

(3)

A Simple Application: Parentheses Balancing

in C, the following characters show up in pairs: (), [], {}, ""

good: {xxx(xxxxxx)xxxxx"xxxx"x}

bad: {xxx(xxxxxx}xxxxx"xxxx"x}

the LISP programming language

(append (pow (* (+ 3 5) 2) 4) 3)

how can we check parentheses balancing?

H.-T. Lin (NTU CSIE) Stacks, Queues, Deques 03/31/2015 2 / 3

(4)

Stack Solution to Parentheses Balancing

inner-most parentheses pair =⇒ top-most plate

’(’: 堆盤子上去 ; ’)’: 拿盤子下來

Parentheses Balancing Algorithm for each c in the input do

if c is a left character push c to the stack else if c is a right character

pop d from the stack and check if match end if

end for

many more sophisticated use in compiler design

H.-T. Lin (NTU CSIE) Stacks, Queues, Deques 03/31/2015 3 / 3

參考文獻

相關文件

How can we write classes for Inte- ger/String/Double/Professor sets of arbi- trary

class methods: exactly the same as class variables intention determined by directly using class names, or by reference TYPE.. run out of paper).. static (compile-time)

sequential search array (or linked list) selection sort array (or linked list) insertion sort linked list (or array) binary search ordered array polynomial merge sparse array on

check type information very strictly by compiler (as opposed to single-object polymorphism): ensure type safety in JVM. Note: type information erased

(a) (15%) Illustrate a scheme (with code or figure) that uses the two stacks and at most O(1) of additional memory to simulate THREE stacks, numbered 1, 2, 3.. In particular,

– Programming methodology that views a program  as consisting of objects that interact with one

   美國華盛頓大學比較文學博士,現為中興大學特聘 教授兼台文所所長、人文與社會科學研究中心主任。香港 嶺南大學Honorary

The existence of cosmic-ray particles having such a great energy is of importance to astrophys- ics because such particles (believed to be atomic nuclei) have very great