Bubble Sorting with Array

Sorting is maximum using for data order and disorder in programming language.

This topic is help in creating report like monthly, daily, yearly etc. Using we can easily find and search data from list.

In this blog, we will work on bubble sort process with examples.

 

Bubble Sorting In 1-d Array

import java.io.*;

class arr5

{

            public static void main(String args[]) throws IOException

            {

                        InputStreamReader in1 = new InputStreamReader(System.in);

                        BufferedReader br = new BufferedReader(in1);

 

                        int[] x = new int[5];

                        int temp;

                        System.out.println(“Enter Array : “);

                        for(int i=0;i<=4;i++)

                        {

                                    x[i] = Integer.parseInt(br.readLine());

                        }

 

                        for(int i=0;i<x.length;i++)

                        {          

                                    for(int j=i+1;j<x.length;j++)

                                    {          

                                                if(x[i] > x[j])

                                                {

                                                            temp = x[i]; 

                                                            x[i] = x[j];

                                                            x[j] = temp;

                                                }

                                    }

                        }

                        System.out.println(“Sorted List:”);

                        for(int i=0;i<=4;i++)

                        {

                                    System.out.println(x[i]);

                        }          

            }          

}

Output:

Enter Array:

23

12

-45

65

6

Sorted List:

-45

6

12

23

65

 

Basic to Advance Level Tutorial.

 

NoTitle
1Work on selection Sorting
2Work on Merge Sorting
3Work on insertion search
4Work on binary search.

 

 

 

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

397total visits,2visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image

EmailEmail
PrintPrint