HackToHell. Powered by Blogger.

Java Program to prove that selection sort is faster than bubble sort

class bubblesort implements Runnable{
int ar[] = new int[10000];
Thread td;
bubblesort(){
int t=0;
for(int i=9999;i>0;i--){
t++;
ar[t]=i;
}
td=new Thread(this,"Gow");
td.start();
}
public void run(){
int t;
for(int i=0;i<9999;i++){
for(int j=0;j<9999-i;j++){
if(ar[j]>ar[j+1]){
t=ar[i];
ar[i]=ar[j+1];
ar[j+1]=t;
}
}
}
System.out.println("Done");
}
}

class selsort implements Runnable{
int ar[] = new int[10000];
Thread td;
selsort(){
int t=0;
for(int i=9999;i>0;i--){
t++;
ar[t]=i;
}
td=new Thread(this,"Gow1");
td.start();
}
public void run(){
int t;
int min=0;
for(int i=0;i<9999;i++){
min=i;
for(int j=i+1;j<10000;j++){
if(ar[j]<ar[min])
min=j;
}
t=ar[i];
ar[i]=ar[min];
ar[min]=t;

}
System.out.println("Done2");
}

}
class check{
public static void main(String args[]){
new bubblesort();
new selsort();
}
}

 

compile as javac  check.java

run as java check

Share on Google Plus

About hacktohell

Love technology.
    Blogger Comment
    Facebook Comment

2 comments:

  1. 6E994624B4
    Exploring new resources online can be incredibly beneficial for expanding your knowledge and skills. For comprehensive tools and information, you should visit the Website regularly to stay updated. It offers a wide range of features designed to assist both beginners and experts. Ensure you take advantage of these resources to enhance your learning experience. Staying informed is key to success in today's digital world.

    ReplyDelete