more enhanced stack sort algorithm