answersLogoWhite

0

bubblesort(int[] unsortedList){ 1)for(int i=1; iunsortedList[j]){ 4) int temp = unsortedList[i]; 5) unsortedList[i] = unsortedList[j]; 6) unsortedList[j] = temp; } } } return unsortedList } Explanation: 1: take each element in unsortedList, one at a time, and call the variable in it i 2:for each i, take each element further down the list one at a time and call this j 3:compare i to j, if i is grater than j, then j should go before anything i should go before so swap them. j will then be the new i, but is still in the correct place in the list because i was up until it saw j. i will be put back where it shopuld go next time round. Example: 1 4 3 7 5 6 I=14 3 7 5 6 I=4>j=3 1 3 4 7 5 6 I=34 7 5 6 I=47 5 6 I=7>j=5 1 3 4 5 7 6 I= 5>j=6 1 3 4 5 7 6 I=7>j=6 1 3 4 5 6 7 return 1 3 4 5 6 7 bubblesort(int[] unsortedList){ 1)for(int i=1; iunsortedList[j]){ 4) int temp = unsortedList[i]; 5) unsortedList[i] = unsortedList[j]; 6) unsortedList[j] = temp; } } } return unsortedList } Explanation: 1: take each element in unsortedList, one at a time, and call the variable in it i 2:for each i, take each element further down the list one at a time and call this j 3:compare i to j, if i is grater than j, then j should go before anything i should go before so swap them. j will then be the new i, but is still in the correct place in the list because i was up until it saw j. i will be put back where it shopuld go next time round. Example: 1 4 3 7 5 6 I=14 3 7 5 6 I=4>j=3 1 3 4 7 5 6 I=34 7 5 6 I=47 5 6 I=7>j=5 1 3 4 5 7 6 I= 5>j=6 1 3 4 5 7 6 I=7>j=6 1 3 4 5 6 7 return 1 3 4 5 6 7

User Avatar

Wiki User

17y ago

Still curious? Ask our experts.

Chat with our AI personalities

BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
RossRoss
Every question is just a happy little opportunity.
Chat with Ross
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach

Add your answer:

Earn +20 pts
Q: About bubble sort
Write your answer...
Submit
Still have questions?
magnify glass
imp