Last active
January 25, 2019 13:56
-
-
Save dogterbox/7524aeb1b87850eeb7980780a2f2814e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
selectionSort <- function(num) { | |
for (i in seq(1, (length(num) - 1))) { | |
index <- i # index of min number | |
for (j in seq(i, length(num))) { | |
if (num[j] < num[index]) { | |
index <- j | |
} | |
} | |
# swap number | |
minNum <- num[index] | |
num[index] <- num[i] | |
num[i] <- minNum | |
} | |
return(num) | |
} | |
randNum <- function(n, start, stop) { | |
rand <- round(runif(n, start, stop)) | |
return(c(rand)) | |
} | |
num <- randNum(100, -50, 50) | |
cat("num: ", num, "\t") | |
cat("num sorted: ", selectionSort(num)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment