stack & queue

Download Stack & Queue

If you can't read please download the document

Post on 14-Jan-2016

40 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

Stack & Queue. Winter-Camp-2011 CSIE.NTNU. N.S.Lin@csie.ntnu@Taiwan. CC – 非商業性 – 相同方式. Stack. 一種串列式資料結構 LIFO (Last In First Out). Stack Sample. Make a Stack. -1. 0. 1. 2. 3. 4. 5. 6. 7. #define SIZE 8 int my_stack[SIZE]; int pointer = -1. if (pointer < 0) null. - PowerPoint PPT Presentation

TRANSCRIPT

  • Stack & QueueWinter-Camp-2011CSIE.NTNUN.S.Lin@csie.ntnu@TaiwanCC

  • StackLIFO (Last In First Out)

  • Stack Sample

  • Make a Stack01234567-1if (pointer < 0) null.if (pointer == SIZE) full.#define SIZE 8int my_stack[SIZE];int pointer = -1

  • QueueFIFO(First In First Out)

  • Queue Sample

  • Make a Queue01234567if (front == rear) null.if (rear == SIZE) full.

  • Circular Queue

  • Stack ApplicationsLISP functions

    Infix to Postfix

  • LISP Functions

  • LISP Functions( ( () () ) )oddp- 5 2+* 2 3

  • LISP Functions( ( () () ) ) - stack stack((((

  • Infix to PostfixInfix : (1 + 2) * 3 + 4Postfix : 1 2 + 3 * 4 +

  • Infix to PostfixUse a StackOutput the numbersPush operators into the stackIf there are operators having higher(or equal) precedence,pop them.When read ) , pop all operators until pop a ( .

  • Infix to PostfixOperator PrecedenceOutside : ( > * = / > + = -Inside : * = / > + = - > (

  • Infix to Postfix( 1 + 2 ) * 3 / 4

    (*+/12+3*4/

  • Queue ApplicationsBFS

  • Test Yourself673 - Parentheses Balance271 - Simply Syntax727 - Equation

  • Test YourselfPractice:Use a Circular Queue

    Sample Input:100200-1420-1-110-10Sample Output:100200420