|
Post by Sylph on Feb 12, 2002 22:57:18 GMT -5
how do we get the answers to the answerless past midterms?
for winter 2001 question 2, this is what i got:
public void deleteRange(int k, int n) throws ListUnderflowException{ LNode node = new LNode(); LNode temp; for (int i = k; i < k+n; i++){ temp = node.next; node.next = null; node = temp; } }
does this answer make sense? what did other people get?
as well, for question 1, for the body, i just put
return root.left.key.compareTo(key) == 0 || root.middle.key.compareTo(key) == 0 || root.right.key.compareTo(key) == 0;
i don't think this one is right.. it says to do it "without using recursion," but what do they mean by that?
does anyone know of a good, representative past exam?? i see exams talking about importing, packages, protected methods, etc. but i didn't learn that yet (i don't think).
for the old paul gries test, winter 2000, why is 1d true?
|
|
|
Post by Sylph on Feb 12, 2002 23:18:13 GMT -5
also, i don't get the picture for paul gries' exam, question 2a.
|
|
|
Post by Sylph on Feb 13, 2002 18:32:33 GMT -5
for the summer 2001 midterm, question 2:
how come for the next() method, u can't just use {return q.dequeue();} and for hasNext(), {return q.size() > 0}? is it cuz u'd be screwing up the given CircularQueue, cuz ur using the address of it? ok... i think i answered my own question. that makes sense now.
|
|
|
Post by Sylph on Feb 13, 2002 21:51:32 GMT -5
hey, isn't anyone doing the past midterms?
for summer 2001, how come CircularQueue's size() returns and object, and how come the next variable in CQIterator is an int, but in the constructor, it goes: next = q.contents[q.head];
shouldn't it be an object, then?
also, what is the purpose of the next variable in the class, what ever type it is?
|
|
|
Post by Majin_Blues on Feb 13, 2002 22:31:40 GMT -5
hey, isn't anyone doing the past midterms? how come CircularQueue's size() returns and object, and how come the next variable in CQIterator is an int, but in the constructor, it goes: next = q.contents[q.head]; shouldn't it be an object, then? i guess people just do the exams on the last minute... ;D as for size(), it can't return an object... it must return an int because it wouldn't make sense to return an object as size (unless you have wrapper classes)... the next variable depends on whether the queue is made as an array or in a vector... it's possible to store ints in arrays but not in vectors (no booleans, ints, longs, etc. in vectors - objects only)
|
|
|
Post by Sylph on Feb 13, 2002 23:58:13 GMT -5
but contents is an array of objects, and i don't think there are any restrictions to what objects can be enqueued in CircularQueue.
|
|
|
Post by Sylph on Feb 14, 2002 0:12:51 GMT -5
oh, no! the TAs and profs don't have office hrs on thursdays, and if i email 'em i know they will just give me a quick answer and not bother to look at the old exam... question 2 doesn't make sense to me; does anyone get why it's like that?
|
|
|
Post by Majin_Blues on Feb 14, 2002 17:13:41 GMT -5
but contents is an array of objects, and i don't think there are any restrictions to what objects can be enqueued in CircularQueue. contents is an array? in that case, you can store anything... if contents was a vector, then you'd be limited to storing objects only... i.e. no storing ints, booleans, etc. in vectors
|
|
|
Post by Sylph on Feb 14, 2002 17:20:50 GMT -5
/** in CQIterator */ int next; next = q.contents[q.head];
/** in CircularQueue */ public Object[] contents;
|
|
|
Post by Evotamer on Feb 14, 2002 19:01:54 GMT -5
Ummm either the prof made a mistake.. or he forgot to cast... That's just my perspective on this... If you look later his return for next() returns an object which is what q.contents[] should be. So Sylph I think you found a mistake .
|
|