R/Select_sort.R

Defines functions Select_Sort

Documented in Select_Sort

#' @title Select sort
#' @description Select sort
#' @param vector a vector
#' @return A sorted vector
#' @export
Select_Sort = function(vector){
  n = length(vector)
  for(i in 1:(n-1)){
    minIndex = i
    for(j in (i+1):n){
      if(vector[minIndex]>vector[j]){
        minIndex = j
      }
    }
    temp = vector[i]
    vector[i] = vector[minIndex]
    vector[minIndex] = temp
  }
  return(vector)
}
engustc/StatComp21048 documentation built on Dec. 24, 2021, 1:26 a.m.