Implementation of Next Fit algorithm