Anonymous user
Sorting algorithms/Comb sort: Difference between revisions
m
Add R code
mNo edit summary |
m (Add R code) |
||
Line 1,809:
[0, 4, 5, 8, 14, 18, 20, 31, 33, 44, 62, 70, 73, 75, 76, 78, 81, 82, 84, 88]
>>> </lang>
=={{header|R}}==
<lang R>
comb.sort<-function(a){
gap<-length(a)
swaps<-1
while(gap>1 & swaps==1){
gap=floor(gap/1.3)
if(gap<1){
gap=1
}
swaps=0
i=1
while(i+gap<=length(a)){
if(a[i]>a[i+gap]){
a[c(i,i+gap)] <- a[c(i+gap,i)]
swaps=1
}
i<-i+1
}
}
return(a)
}
</lang>
=={{header|Racket}}==
|