Tuesday, March 21, 2006

Mergesort algorithm implementation

I'm reading Wrox's Beginning Algorithms, an exciting book. With this book, you can learn how to implement iterator, list, queue, stack, ... from scrach but the one I like in this book is it used unit testing and source code is written in Java. (I'm using TestNG, instead of JUnit as in the book)

As any books, this book has some typos but it's a not big problem. The biggest problem I found at this time, it's in mergesort algorithm implementation. The authors forgot to check if the list is empty so it doesn't need to sort. This causes an IndexOutOfBoundsException while try to mergesort sublists.

No problem, I'm continuing to read it. Just for fun! :-)

But keep it in your mind (if you want to read this book), add the following code fragment at the begginning of mergesort(List list, int start, int end) method

if (end < start) {
return list;

No comments: