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

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

View Full Document Right Arrow Icon
CMPSCI 187: Programming With Data Structures Lecture 13: Java’s Stack Class and Some Mistakes 7 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
Java’s Stack Class and Some Mistakes • Issues in Project #3 • Generics Again, and a Correction • Constructors and Inheritance • Java’s Stack Class -- the API • Java’s Stack Class -- the Source Code
Background image of page 2
Issues With Project #3 • This is a lecture to correct some mistakes • To start with Project #3 -- here’s one of yours. One student implemented the dropout stack by removing element 0 of the array (the bottom), then moving every element of the stack down one space in the array to make room for the new top element. • What’s wrong with this? The input/output behavior is exactly what is speciFed, but we also speciFed O(1) time for each operation and this push is O(n) if there are n spaces in the array. • The whole idea is not to move lots of elements. So when we push into a full array, and have to delete the bottom element, the bottom position changes . This is the essential feature of a circular array.
Background image of page 3

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

View Full DocumentRight Arrow Icon
More Issues With Project #3 • Remember that your code must conform to the properties we need to test it. Don’t use packages, give your .java Fles the right names (now that they are correct on the web site), and make sure that the method signatures agree with the ones in L&C’s StackADT interface. • Your DropoutStack class should be structurally very much like L&C’s ArrayStack class. Both are generic classes that have to create an array of elements of their base type. The constructor for such a class has a particular form that you should copy exactly. • Your class EmptyCollectionException is very simple to deFne because the only difference between an EmptyCollectionException and a RuntimeException is the name. All you need in your deFnition is the declaration line and a zero-parameter constructor with no code.
Background image of page 4
Generics Again, and a Correction • We want to use generics in order to get their fexibility, but they can be conFusing. L&C try to give the simplest explanation they can to allow us to use them, and I think they mostly succeed iF we are willing to trust them and Follow their usage. But it’s worth looking a little more closely at them. • Vocabulary helps.
Background image of page 5

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

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

Page1 / 14

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

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

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