shellsort
shellsort
import java.util.Scanner;
/// Java implementation of ShellSort
class ShellSort
{
/* An utility function to print array of size n*/
static void printArray(int arr[])
{
int n = arr.length;
for (int i=0; i<n; ++i)
System.out.print(arr[i] + " ");
System.out.println();
}
// Driver method
public static void main(String args[])
{
int n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of elements you want to store:
");
//reading the number of elements from the that we want to enter
n=sc.nextInt();
//creates an array in the memory of length 10
int[] arr = new int[n];
System.out.println("Enter the elements of the array: ");
for(int i=0; i<n; i++)
{
//reading array elements from the user
arr[i]=sc.nextInt();
}
System.out.println("Enter Array before sorting");
/*
Output:
Enter the number of elements you want to store: 6
Enter the elements of the array:
45 12 78 34 23 10
Enter Array before sorting
Array before sorting
45 12 78 34 23 10
Array after sorting
10 12 23 34 45 78
*/