Sunday, September 4, 2016

Java Program For Bubble Sort

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package SeleniumMakeItEasy;

import org.apache.commons.lang3.ArrayUtils;

public class BubbleSort{
public static void main(String[] args){
int[] a = {2,3,2,5,3,3,6,1,2,5};
int l = a.length;

for(int i=0;i<l; i++){

for(int j=0; j<l-1; j++){
if(a[j]>a[j+1]){
a[j] = a[j] + a[j+1];
a[j+1] = a[j] - a[j+1];
a[j] = a[j] - a[j+1];
}else if(a[j]==a[j+1]){
a = ArrayUtils.remove(a,j);
l = a.length;
}
}
}
for(int s: a){
System.out.println(s);
}

}
}


Bhanu Namikaze

Author & Editor

Bhanu Namikaze is an Ethical Hacker, Passionate Blogger, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors, Surfing and Social Networking. Feel Free To Contact Me @ Bhanu.

0 comments:

Post a Comment

Popular Posts

Copyrights @ Interview Questions.Me - Blogger Templates Designed by Templateism - Distributed By Protemplateslab

  • (91) 5544 654942
  • Bhanu@HackingDream.net
  • Interview Questions

Copyrights @ Interview Questions.Me -A Site By Bhanu In Association With Hacking Dream