Tuesday, June 30, 2015

Custome Sorting Program In Arrays

if you have any query please comment bellow :



import java.util.Scanner;

public class ArraySort
{

public static void main(String[] args)
{
Scanner scn=new Scanner(System.in);
System.out.println("type size for array");
int size=scn.nextInt();

int [] arr=new int[size];
for(int i=0;i<size;i++)
{
System.out.print("type no. for sorting :");
arr[i]=scn.nextInt();
}
int limit=size-1;
boolean flag=false;
int temp;
for(int i=0;i<limit;i++)
{
for(int j=0;j<limit-i;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
flag=true;
}
}
if(flag==false)break;
else flag=false;

}
System.out.println("Sorted array are");
for(int i=0;i<size;i++)
{
System.out.println(arr[i]);
}

}

}

0 comments:

Post a Comment