Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26
  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: Sort through array, finding pairs.

    Add some lines of code that parallel the swapping code you've used, but do it to the other array.

    Where you have a use b and for temp use tempb

  2. #22
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Re: Sort through array, finding pairs.

    Quote Originally Posted by Norm View Post
    Add some lines of code that parallel the swapping code you've used, but do it to the other array.

    Where you have a use b and for temp use tempb
    add that to the same method, bubblesort()? That means that i should pass the array containing the strings to that method?

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: Sort through array, finding pairs.

    Yes you would need to pass all the arrays that you want to keep in synch so their contents can be moved in parallel.

  4. #24
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Re: Sort through array, finding pairs.

    I did this and so far it's working. Is there anything blatantly wrong that will come back to bite me in the ass?

    Java Code:
    public static void bubblesort(int[] a, String[] b)
    	{
    		boolean swapped = true;
    		int temp;
    		String tempb; 
    		while(swapped)
    		{
    		swapped=false; 
    		for(int i=0; i<a.length-1;i++)
    		{
    			 
    			if(a[i] > a[i+1])
    			{
    				temp = a[i];
    				tempb = b[i];
    				a[i] = a[i+1];
    				b[i] = b[i+1];
    				a[i+1] = temp;
    				b[i+1] = tempb; 
    				swapped = true;
    			}
    			
    			
    			
    			
    			}
    			 
    		}
    		
    		System.out.println("Zips sorted:" + Arrays.toString(a)); 
    		
    		for(int bl=0;bl<b.length;bl++)
    		{
    			System.out.println(b[bl]); 
    		}
    	
    	
    	
    	}

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: Sort through array, finding pairs.

    If it works, it's probably fine.

  6. #26
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Re: Sort through array, finding pairs.

    It does, thank you.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Need help with Array.sort()
    By Kinney.j in forum New To Java
    Replies: 1
    Last Post: 10-16-2011, 06:51 AM
  2. Algorithm for finding max and min in an array.
    By Shyamz1 in forum New To Java
    Replies: 4
    Last Post: 10-04-2011, 10:45 PM
  3. Finding the Mode in An Array
    By carlodelmundo in forum New To Java
    Replies: 23
    Last Post: 10-31-2010, 12:44 PM
  4. sort array >> need help
    By hongi in forum New To Java
    Replies: 4
    Last Post: 04-25-2010, 09:37 PM
  5. Finding a the max value of the array using a for loop
    By soccer_kid_6 in forum New To Java
    Replies: 1
    Last Post: 04-11-2010, 11:25 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
  •