pub fn pigeonhole_sort(list: &[i32]) -> Result<Vec<i32>,String> {
if list.is_empty() {
return Err("Cannot use pigeonhole sort on an empty list!".to_string());
}
let max = list.iter().max().unwrap();
let min = list.iter().min().unwrap();
let mut result = list.to_vec();
let size = max - min + 1;
let mut holes = vec![0;size as usize];
for value in &result {
let index = value - min;
holes[index as usize] += 1;
}
let mut i = 0;
for count in 0..size {
while holes[count as usize] > 0 {
holes[count as usize] -= 1;
result[i] = count + min;
i += 1;
}
}
Ok(result)
}