Rust program to sort an array in ascending order using selection sort

Rust program to sort an array in ascending order using selection sortI hope we can formalize this useful article. You can also see how the purchase is used.

Rust program to sort an array in ascending order using selection sort

Rust program to sort an array in ascending order using selection sort

// Rust program to sort an array in ascending order 
// using selection sort

fn main() 
{
    let mut arr:[usize;5] = [5,1,23,11,26];
    let mut i:usize=0;
    let mut j:usize=0;
    
    let mut min:usize=0;
    let mut temp:usize=0;
    
    println!("Array before sorting: {:?}",arr);
    while i <= 4 
    {
		min = i;
		j   = i + 1; 
		
		while j <= 4 
		{
			if arr[j] < arr[min] {
				min = j;
			}
			j=j+1; 
		}
		temp = arr[i];
		arr[i] = arr[min];
		arr[min] = temp;
		
		i=i+1;
	}
	println!("Array after sorting: {:?}",arr);
}
Array before sorting: [5, 1, 23, 11, 26]
Array after sorting: [1, 5, 11, 23, 26]

Final Words

We hope you find the Rust program to sort an array in ascending order using selection sort article very useful. If this article was helpful to you, we ask that you help your friends benefit too.

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

Share on:

Leave a Comment