Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x<-c(4,7,2,9,1,5,3,23,6)
- SelectSort<-function(x,decreasing=F) {
- n <- length(x)
- for(i in 1:(n-1)){
- if(decreasing){
- nmin<-i
- for(j in (i+1):n){
- if(x[j] < x[nmin]){
- nmin<-j
- }
- }
- temp<-x[i]
- x[i]<-x[nmin]
- x[nmin]<-temp
- }
- else{
- nmax<-i
- for(j in (i+1):n){
- if(x[j]>x[nmax]){
- nmax<-j
- }
- temp<-x[i]
- x[i]<-x[nmax]
- x[nmax]<-temp
- }
- }
- }
- }
- print(SelectSort(x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement