import java.util.Scanner;
class BubbleSort{
public
static void main(String[] a){
int
numberCount;
System.out.print("Enter
how many numbers you want to sort:");
Scanner
sc=new Scanner(System.in);
numberCount=sc.nextInt();
int
numberSet[]=new int[numberCount];
System.out.println("Enter
numbers one by one");
for(int
x=0;x<=numberCount-1;x++){
numberSet[x]=sc.nextInt();
}
int
set[]={1,23,54,87,12,34};
//int
set[]=new int[10];
BubleSort
b1=new BubleSort();
System.out.println("Before
sorting"+set.length);
for(int
x:numberSet){
System.out.print(x+" ");
}
b1.sortSet(numberSet);
//System.out.println(a);
System.out.println("\nAfter
sorting");
for(int
x:numberSet){
System.out.print(x+" ");
}
}
public
void sortSet(int list[]){
for(int
i=0;i<list.length-1;i++){
for(int
j=0;j<list.length-i-1;j++){
if(list[j]>list[j+1]){
int
temp=list[j+1];
list[j+1]=list[j];
list[j]=temp;
}
}
}
}
}
No comments:
Post a Comment