Java implementation in Data Structures Algorithm