Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
gnomesort <- function(x)
|
||||
{
|
||||
i <- 1
|
||||
j <- 1
|
||||
while(i < length(x))
|
||||
{
|
||||
if(x[i] <= x[i+1])
|
||||
{
|
||||
i <- j
|
||||
j <- j+1
|
||||
} else
|
||||
{
|
||||
temp <- x[i]
|
||||
x[i] <- x[i+1]
|
||||
x[i+1] <- temp
|
||||
i <- i - 1
|
||||
if(i == 0)
|
||||
{
|
||||
i <- j
|
||||
j <- j+1
|
||||
}
|
||||
}
|
||||
}
|
||||
x
|
||||
}
|
||||
gnomesort(c(4, 65, 2, -31, 0, 99, 83, 782, 1)) # -31 0 1 2 4 65 83 99 782
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
gnomeSort <- function(a)
|
||||
{
|
||||
i <- 2
|
||||
j <- 3
|
||||
while(i <= length(a))
|
||||
{
|
||||
if(a[i - 1] <= a[i])
|
||||
{
|
||||
i <- j
|
||||
j <- j + 1
|
||||
}
|
||||
else
|
||||
{
|
||||
a[c(i - 1, i)] <- a[c(i, i - 1)]#The cool trick mentioned above.
|
||||
i <- i - 1
|
||||
if(i == 1)
|
||||
{
|
||||
i <- j
|
||||
j <- j + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
a
|
||||
}
|
||||
#Examples taken from the Haxe solution.
|
||||
#Note that R can use <= to compare strings.
|
||||
ints <- c(1, 10, 2, 5, -1, 5, -19, 4, 23, 0)
|
||||
numerics <- c(1, -3.2, 5.2, 10.8, -5.7, 7.3, 3.5, 0, -4.1, -9.5)
|
||||
strings <- c("We", "hold", "these", "truths", "to", "be", "self-evident", "that", "all", "men", "are", "created", "equal")
|
||||
Loading…
Add table
Add a link
Reference in a new issue