Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. public double bubblesort() {
  2. int unsortedArray[]=new int[10];
  3. int temp, counter, index,length=unsortedArray.length;
  4.  
  5. for(int i=0;i<length-1;i++){
  6. unsortedArray[i]=(int) (Math.random()*100);
  7. System.out.print(""+unsortedArray[i]+", ");
  8. }
  9.  
  10.  
  11. acc.setEnabled(false);
  12. proglbl.setText("Bubblesort benchmark");
  13. jpb.setValue(0);
  14. jpb.setMaximum(length-1);
  15. reslbl.setText("");
  16.  
  17.  
  18. for(counter=0; counter<length; counter++) {
  19. for(index=0; index<length-1-counter; index++) {
  20. if(unsortedArray[index] < unsortedArray[index+1]) {
  21. temp = unsortedArray[index];
  22. unsortedArray[index] = unsortedArray[index+1];
  23. unsortedArray[index+1] = temp;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement