Question text in black, answers in blue.
Yes. I've changed the HW#2 assignment page to fix this, and you get an extra point on the final exam for catching the mistake first.
No, you are allowed to read them from the input string only once. If you put them in your internal memory and read them from there later, that is fine -- in fact the internal memory would not be of much use otherwise!
Could I use a temporary string as my internal memory?
No, your only internal memory is what I gave you -- one stack and one queue in Question 7, and one stack along in Question 8.
I looked at it, and while your methods are all O(1) time you are not implementing a dropout stack at all but an ordinary stack. When a dropout stack exceeds its capacity it must remove its bottom element, but your code doesn't do that. As we've seen, a singly linked list has trouble removing elements from both ends.
Could I use a doubly linked list?
We will do that eventually, but for now no, just
do the best you can with the LinearNode
class that we
have.
w.length
-- you can only get the length of a
String
by saying w.length( )
because length
is a
method.
You're right -- this was a typo on my part which
has
now been corrected. As you say, we can get the length of an array
with
just By the way, I see that you've noticed that your compiler contains a
very sophisticated validity checker for Java code, so that even if you
are writing a homework assignment on paper that doesn't need to be
compiled,
it can be useful to write your in your normal Java environment where
the
compiler can check it. The only difficulty with this is that paper
assignments often assume that particular other code is present and it
might
not be.
x.length
but String
objects require
x.length( )
. You get a point on the final for catching
this.
The first, both a stack and a queue. You use just a stack in Question 8, and in fact it can't be done with just a queue if you are just reading the input once from left to right. (This is sometimes proved in CMPSCI 401.)
Last modified 15 October 2011