0% found this document useful (0 votes)
11 views1 page

Java Program For Implementation of Selection Sort

This document contains a Java program that implements the Selection Sort algorithm. The program sorts an array of integers by repeatedly finding the minimum element from the unsorted portion and swapping it with the first unsorted element. It includes a main function that demonstrates the sorting of a sample array.

Uploaded by

Prangobinda Sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Java Program For Implementation of Selection Sort

This document contains a Java program that implements the Selection Sort algorithm. The program sorts an array of integers by repeatedly finding the minimum element from the unsorted portion and swapping it with the first unsorted element. It includes a main function that demonstrates the sorting of a sample array.

Uploaded by

Prangobinda Sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Java program for implementation of Selection Sort

class SelectionSort
{
void sort(int a[])
{
int n = a.length;
// One by one move boundary of unsorted subarray
for (int i = 0; i < n - 1; i++)
{
// Find the minimum element in unsorted array
int min_idx = i;
for (int j = i + 1; j < n; j++)
{
if (a[j] < a[min_idx])
min_idx = j;
}
// Swap the found minimum element with the first element
int temp = a[min_idx];
a[min_idx] = a[i];
a[i] = temp;
}
}
// main function
public static void main(String args[])
{
SelectionSort ob = new SelectionSort();
int a[] = { 64, 25, 12, 22, 11 };
ob.sort(a);
int n = a.length;
for (int i = 0; i < n; ++i)
System.out.print(a[i] + " ");
}
}

You might also like