Data structure and algorithm in Java