data base structures make some modifications to the java code below that either make 5150835
Data Base Structures
Make some modifications to the java code below that either makes the code more efficient or replace some lines of code with alternative way to get the same outcome.
Thanks.
/*
* Java Program to Implement Selection Sort
*/
import java.util.Scanner;
/* Class SelectionSort */
public class SelectionSort
{
private static Scanner scan;
/* Selection Sort function */
public static void sort( int arr[] ){
int N = arr.length;
int i, j, pos, temp;
for (i = 0; i
{
pos = i;
for (j = i+1; j
{
if (arr[j]
{
pos = j;
}
}
/* Swap arr[i] and arr[pos] */
temp = arr[i];
arr[i] = arr[pos];
arr[pos]= temp;
}
}
/* Main method */
public static void main(String[] args)
{
scan = new Scanner( System.in );
System.out.println(“Selection Sort Testn”);
int n, i;
/* Accept number of elements */
System.out.println(“Enter number of integer elements”);
n = scan.nextInt();
/* Create integer array on n elements */
int arr[] = new int[ n ];
/* Accept elements */
System.out.println(“nEnter “+ n +” integer elements”);
for (i = 0; i
arr[i] = scan.nextInt();
/* Call method sort */
sort(arr);
/* Print sorted Array */
System.out.println(“nElements after sorting “);
for (i = 0; i
System.out.print(arr[i]+” “);
System.out.println();
}
}