I'm just starting a search for a library or code sample for grouping numbers together based on their distance from one another. For instance, in the set{1,2,4,25,28,29}, is there an algorithm that would identify two groups of numbers subsetA{1,2,4} and subsetB{25,28,29}?

Nothing really came up in my google search, but I figure there has to be something out there. Is there another name for "number grouping algorithm"?