# Thread: Sort through array, finding pairs.

1. ## 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. Senior Member
Join Date
Feb 2012
Posts
219
Rep Power
3

## Re: Sort through array, finding pairs.

Originally Posted by Norm
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. ## 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. Senior Member
Join Date
Feb 2012
Posts
219
Rep Power
3

## 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. ## Re: Sort through array, finding pairs.

If it works, it's probably fine.

6. Senior Member
Join Date
Feb 2012
Posts
219
Rep Power
3

## Re: Sort through array, finding pairs.

It does, thank you.

Page 2 of 2 First 12

#### Posting Permissions

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