This is my Logic,The user input number,A number is stored sorting wise,so time complexity decrease.Here you use many sorting algorithm then stored a number.
CODING:
import java.util.*;
class sort{
public static void main(String args[]){
Scanner n=new Scanner(System.in);
int arry[],temp;
System.out.print("How Many Enter Number : ");
for(int i=n.nextInt();i<arry.length;i++){
System.out.print("Enter Number : ");
arry[i]=n.nextInt();
for(int k=i;k>0;k--){
if(arry[k-1]>arry[k]){
temp=arry[k-1];
arry[k-1]=arry[k];
arry[k]=temp;}
}
}
System.out.print("After Sorting Array :" + Arrays.toString(arry));
}
}
class sort{
public static void main(String args[]){
Scanner n=new Scanner(System.in);
int arry[],temp;
System.out.print("How Many Enter Number : ");
for(int i=n.nextInt();i<arry.length;i++){
System.out.print("Enter Number : ");
arry[i]=n.nextInt();
for(int k=i;k>0;k--){
if(arry[k-1]>arry[k]){
temp=arry[k-1];
arry[k-1]=arry[k];
arry[k]=temp;}
}
}
System.out.print("After Sorting Array :" + Arrays.toString(arry));
}
}
Comments
Post a Comment