Sorting and array with indexes implemented