modify selection sort with stack