sorted array code