Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Bi-Directional Bubble Sort in Java
WhatsApp
Alagunila Meganathan
5y
9.7
k
0
2
25
Blog
BidirectionalBubbleSort.rar
Introduction
In this blog, I am going to explain the program for Bidirectional Bubble Sort in Java
Software Requirements
Java, Notepad
Programming
public
class
BidirectionalBubbleSort {
public
static
void
main(String a[]) {
int
i;
int
array[] = {
12
,
9
,
4
,
99
,
120
,
1
,
3
,
10
};
System.out.println(
"\n\n RoseIndia\n\n"
);
System.out.println(
" Selection Sort\n\n"
);
System.out.println(
"Values Before the sort:\n"
);
for
(i =
0
; i < array.length; i++)
System.out.print(array[i] +
" "
);
System.out.println();
bidirectionalBubble_srt(array, array.length);
System.out.print(
"Values after the sort:\n"
);
for
(i =
0
; i < array.length; i++)
System.out.print(array[i] +
" "
);
System.out.println();
System.out.println(
"PAUSE"
);
}
public
static
void
bidirectionalBubble_srt(
int
array[],
int
n) {
int
j;
int
st = -
1
;
while
(st < n) {
st++;
n--;
for
(j = st; j < n; j++) {
if
(array[j] > array[j +
1
]) {
int
T = array[j];
array[j] = array[j +
1
];
array[j +
1
] = T;
}
}
for
(j = n; --j >= st;) {
if
(array[j] > array[j +
1
]) {
int
T = array[j];
array[j] = array[j +
1
];
array[j +
1
] = T;
}
}
}
}
}
Output
Java
sort
Bubble Sort
Up Next
How to compare strings in Java
Ebook Download
View all
Solutions Manual to Objects First with Java – A Practical Introduction using BlueJ
Read by 1.8k people
Download Now!
Learn
View all
Membership not found