Created sorting algorithm