added copied pseudocode to sort