Today I reviewed my answers for EIMACS test 21. I started learning about stacks and queues. I also came across this really strange exercise. The code started off as: The interesting thing is that this code already works perfectly, since LinkedList already has the methods #add(), #isEmpty(), #peek(), #pop(), and #remove(). However, their solution overrides these methods and re-implements them to have practically identical functionality:I'm not really sure what the point of that was.
I also learned about PriorityQueues, which take Compareable objects and rather than popping the first or last element added, they pop the element with the lowest value as determined by #compareTo(). The way they explained it was kind of weird, but I assume that this type of data structure does have use in actual applications.
I also learned about PriorityQueues, which take Compareable objects and rather than popping the first or last element added, they pop the element with the lowest value as determined by #compareTo(). The way they explained it was kind of weird, but I assume that this type of data structure does have use in actual applications.
Since we just touched on this in conversation in class today (12/17), I'm going to reply to this now rather than wait until the weekend.
ReplyDeleteRegarding your comment, "I'm not really sure what the point of that was", I'll respond with one of my favorite quotes:
“We have to reinvent the wheel every once every once in a while, not because we need a lot of wheels; but because we need a lot of inventors.” -- Bruce Joyce
In what is certainly among the best computer science books ever written, The C Programming Language by Brian Kernighan and Dennis Ritchie, many of the exercises basically ask you the reader to re-implement utilities from the C standard library. Why would you want to do that, you may ask? Aren't those utilities already available in the standard library? Why yes, but the assumption is that you want to become a good enough programmer that you could write a standard library.
Oh, and another response to the "I'm not really sure what the point of that was". Suppose you have an API that is already defined, and you what to re implement it. It may very well be that your LinkedList already has the behavior you want, but not with the names that your API calls for.
ReplyDelete