notes10 - CSE 2320 Notes 10: Stacks and Queues (Last...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 2320 Notes 10: Stacks and Queues (Last updated 10/17/11 4:35 PM) Sedgewick 4.2, 4.4, 18.1, 4.3, 4.5, 4.7 10.A. S TACKS Abstraction (Last-In, First-Out) and Operations P USH P OP T OP E MPTY Policies Correspond to Code (usually (1)) 1. Direction of growth in array 2. What does stack pointer indicate? a. Next available element: 1 2 3 4 5 x y z SP E MPTY : return sp==0; P USH (x): A[sp++]=x; P OP : return A[--sp]; T OP : return A[sp-1]; b. Most recently pushed element: 1 2 3 4 5 x y z SP E MPTY : return sp==(-1); P USH (x): A[++sp]=x; P OP : return A[sp--]; T OP : return A[sp]; Sedgewick 4.4: Also easy to implement using a linked list. SP . . . 2 Applications 1. Run-time environment for programming languages. 2. Compilers/parsing 3. Depth-first search on graphs (Notes 14). 10.B. R AT- IN- A-M AZE U SING A S TACK (D EPTH-F IRST S EARCH ) . . . . . . . . . . . . . . . . . . # . # # # # # ^ ^ ^ ^ ^ ^ ^ ^ . . # . # . . . # . ^ . . . . . . . . # # # . # # # . ^ ^ ^ . ^ ^ ^ . . . . . . # . . . ^ . ^ . ^ . ^ . . . # # # . ^ . ^ ^ ^ . ^ . . . . . . # . . . . . . . . . . . # # # . ^ ^ ^ ^ ^ ^ ^ . . . . . . # . . . ^ . . . . . ^ . . ^ . # # # . ^ ^ ^ . ^ . ^ ^ ^ . . ^ . # . ^ . ^ . . . ^ . ^ . . . . # # # . ^ ^ ^ ^ ^ . ^ ^ ^ . . . # . . . . . . . . . . . . . . . # # # # # # # # # . . . . . . . . . # . . . . . . . . . # # # # # # # . . . . . . . . . . . . . . . . . . Array initially contains 0/1 for each position....
View Full Document

Page1 / 7

notes10 - CSE 2320 Notes 10: Stacks and Queues (Last...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online