Midterm Review1.6

Midterm Review1.6 - Array-based Stack A simple way of...

Info iconThis preview shows pages 1–5. 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

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: Array-based Stack A simple way of implementing the Stack ADT uses an array We add elements from left to right A variable keeps track of the index of the top element Algorithm size() return t + 1 Algorithm pop() if isEmpty() then throw EmptyStackException else t t-1 return S[t + 1] … S 0 CSE 2011 Prof. J. Elder 1 2 t - 26 - Last Updated: 1/7/10 10:14 AM Queues Chapters 5.2-5.3 CSE 2011 Prof. J. Elder - 27 - Last Updated: 1/7/10 10:14 AM Array-Based Queue Use an array of size N in a circular fashion Two variables keep track of the front and rear f index of the front element r index immediately past the rear element Array location r is kept empty normal configuration Q 012 f r wrapped-around configuration Q 012 CSE 2011 Prof. J. Elder r f - 28 - Last Updated: 1/7/10 10:14 AM Queue Operations We use the modulo operator (remainder of division) Algorithm size() return (N f + r) mod N Algorithm isEmpty() return (f = r) Note: N f + r = (r + N ) f Q 012 f 012 r r Q CSE 2011 Prof. J. Elder f - 29 - Last Updated: 1/7/10 10:14 AM Linked Lists Chapters 3.2 – 3.3 CSE 2011 Prof. J. Elder - 30 - Last Updated: 1/7/10 10:14 AM ...
View Full Document

Page1 / 5

Midterm Review1.6 - Array-based Stack A simple way of...

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

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