Results 1 to 2 of 2
  1. #1
    Hotspotmar is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default Bubble sort Algorithm

    I need some help with this code the out put isn't the required output, the required output being the Array sorted.


    Java Code:
     class Derpyface {
    public static void main(String[] args){
    	int derp[]= {16, 100, 205, 8, 1, 3, 2, 5, 7, 6, 15, 10, 14};
    	
    	for(int num = 0; num < derp.length; num++ ){
    		System.out.print(derp[num] + ",");
    	}
    	
    	for(int array = derp.length -1; array > 0; array--){		
    		for (int x = 0; x < derp.length -1; x++){
    			int temp1 = derp[x];
    			int temp2 = derp[x+1];
    			if(derp[x] > derp[x+1]){ 
    				derp[x] = temp2;
    				derp[x=1]= temp1;
    			}
    		}
    	}
    	System.out.println();
    	for(int x = 0; x < derp.length; x++){
    	System.out.print(derp[x] + ",");
    	
    
    }
    
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default Re: Bubble sort Algorithm

    Your loop boundaries are incorrect and this:

    Quote Originally Posted by Hotspotmar View Post
    Java Code:
    			derp[x=1]= temp1;
    ... doesn't make sense at all.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Bubble-sort method
    By Mapisto in forum New To Java
    Replies: 10
    Last Post: 12-27-2011, 09:43 PM
  2. Bubble sort
    By pineapple in forum New To Java
    Replies: 3
    Last Post: 04-25-2009, 12:45 AM
  3. Trouble w/ Bubble Sort
    By bri1547 in forum New To Java
    Replies: 4
    Last Post: 08-01-2008, 04:41 PM
  4. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM
  5. need help with bubble sort
    By lowpro in forum New To Java
    Replies: 3
    Last Post: 12-17-2007, 05:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •