[Data Structure] Bubble Sort

  1. Compare adjacent elements. If the first one is bigger than the second one, swap the two of them.
  2. Do the same work for each pair of adjacent elements, from the first pair at the beginning to the last pair at the end. At this point, the last element should be the largest number.
  3. Repeat the above steps for all elements except the last one.
  4. Repeat the above steps for fewer and fewer elements each time until there is no pair of numbers to compare.
public class bubbleSort {
public bubbleSort(){
int a[]={49,38,65,97,76,13,27,49, 78,34,12,64,5,4,62,99,98,54,56,17,18,23,34,15,35,25,53,51};
int temp=0;
for(int i=0;i for(int j=0;j if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+ 1]=temp;
}
}
}
for(int i=0;i System.out.println(a [i]);
}
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5033 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.