Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.*;
- import java.util.*;
- public class BubbleSortIA{
- public static void main(String[] args) {
- int array[]={4,-1,2,9,5};
- // int temp; //You can do this using temp or without temp variable
- for (int i=0;i<array.length -1; i++) {
- for (int j=0;j<array.length - 1; j++) {
- if(array[j+1]<array[j]){
- // temp = array[j+1];
- // array[j+1]=array[j];
- // array[j]=temp;
- array[j+1]=array[j]^array[j+1];
- array[j]=array[j]^array[j+1];
- array[j+1]=array[j]^array[j+1];
- }
- }
- }
- for (int X : array) {
- System.out.print(X+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement