12 - CMPSCI 187: Programming With Data Structures Lecture...

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

View Full Document Right Arrow Icon
CMPSCI 187: Programming With Data Structures Lecture 12: Implementing Stacks With Linked Lists 5 October 2011
Background image of page 1

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

View Full DocumentRight Arrow Icon
Implementing Stacks With Linked Lists • Overview: The LinkedStack • The Fields and Constructors • The push Method • The pop Method • The Other Methods • L&C’s Version of the Maze Search
Background image of page 2
Overview: The LinkedStack • Now that we know how linear linked structures work, we can see that they are well suited to implement a stack. • We only need to change pointers on elements near the top to push or pop, giving us O(1) time for these operations in the worst case. (The ArrayStack needed O(n) time to resize on some pushes, though these operations only took O(1) time per push on average.) • We’ll use the LinearNode class the we deFned last lecture, where a node points to the next node and points to its contents, from some class T. • The ArrayStack already kept track of its size through the Feld top , but we will need a Feld to keep the size of our stack explicitly.
Background image of page 3

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

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

Page1 / 8

12 - CMPSCI 187: Programming With Data Structures Lecture...

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

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