Ruby program to sort an array in descending order using selection sort

Hi Hello, What I am going to do in this article I will see in detail about Ruby program to sort an array in descending order using selection sort. This article is a favorite of everyone and many people are suffering without knowing what the reason is. This article will be very useful for them.

Ruby program to sort an array in descending order using selection sort

Ruby program to sort an array in descending order using selection sort

# Ruby program to sort an array in descending order 
# using selection sort

arr = [12,39,49,87,68];

i=0;
j=0;
t=0;
max=0;

while(i<5)
    max=i;
    j=i + 1
    while(j<5)
        if(arr[j]>arr[max])
            max=j;
        end
        j=j + 1;
    end
    
    t=arr[i];
    arr[i]=arr[max];
    arr[max]=t;
    
    i=i + 1;
end

i=0;
print "Sorted Array in descending order: \n";
while(i<5)
    print arr[i]," ";
    i=i+1;
end
Sorted Array in descending order: 
87 68 49 39 12 

Final Words

By knowing clearly about Ruby program to sort an array in descending order using selection sort through this article. If you have any doubts please leave a comment via the comment box. Thank You.

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment