lec13a - Stacks public interface Stack cfw_ public boolean...

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

View Full Document Right Arrow Icon
Stacks public interface Stack { public boolean empty(); public Object peek(); public void push(Object theObject); public Object pop(); }
Background image of page 1

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

View Full DocumentRight Arrow Icon
Derive From A Linear List Class ArrayLinearList Chain
Background image of page 2
Derive From ArrayLinearList stack top is either left end or right end of linear list empty() => isEmpty() O(1) time peek() => get(0) or get(size() - 1) O(1) time 0 1 2 3 4 5 6 a b c d e
Background image of page 3

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

View Full DocumentRight Arrow Icon
Derive From ArrayLinearList when top is left end of linear list push(theObject) => add(0, theObject) O(size) time pop() => remove(0) O(size) time 0 1 2 3 4 5 6 a b c d e
Background image of page 4
Derive From ArrayLinearList when top is right end of linear list push(theObject) => add(size(), theObject) O(1) time pop() => remove(size()-1) O(1) time use right end of list as top of stack 0 1 2 3 4 5 6 a b c d e
Background image of page 5

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

View Full DocumentRight Arrow Icon
Derive From Chain stack top is either left end or right end of linear list empty() => isEmpty() O(1) time a b c d e null firstNode
Background image of page 6
Derive From Chain a b c d e null firstNode when top is left end of linear list peek() => get(0) O(1) time push(theObject) => add(0, theObject) O(1) time pop() => remove(0) O(1) time
Background image of page 7

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

View Full DocumentRight Arrow Icon
Derive From Chain a b c d e null firstNode when top is right end of linear list peek() => get(size() - 1) O(size) time push(theObject) => add(size(), theObject) O(size) time pop() => remove(size()-1) O(size) time use left end of list as top of stack
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 26

lec13a - Stacks public interface Stack cfw_ public boolean...

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

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