Sorting algorithms/Permutation sort: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
ReeceGoding (talk | contribs) m (→RcppAlgos: Improved syntax.) |
||
Line 2,035: | Line 2,035: | ||
RcppAlgos lets us do this at the speed of C++ and with some very short code. The while loop with no body strikes me as poor taste, but I know of no better way. |
RcppAlgos lets us do this at the speed of C++ and with some very short code. The while loop with no body strikes me as poor taste, but I know of no better way. |
||
<lang rsplus>library(RcppAlgos) |
<lang rsplus>library(RcppAlgos) |
||
permuSort<-function(list) |
permuSort <- function(list) |
||
{ |
{ |
||
iter<-permuteIter(list) |
iter <- permuteIter(list) |
||
while(is.unsorted(iter$nextIter())){}#iter$nextIter advances iter to the next iteration and returns it. |
while(is.unsorted(iter$nextIter())){}#iter$nextIter advances iter to the next iteration and returns it. |
||
iter$currIter() |
iter$currIter() |
||
} |
} |
||
test<-sample(10) |
test <- sample(10) |
||
print(test) |
print(test) |
||
permuSort(test)</lang> |
permuSort(test)</lang> |
||
{{out}} |
{{out}} |
||
<pre>#Output |
<pre>#Output |
||
> test<-sample(10) |
> test <- sample(10) |
||
> print(test) |
> print(test) |
||
[1] 8 10 6 2 9 4 7 5 3 1 |
[1] 8 10 6 2 9 4 7 5 3 1 |