Question

write a method bubbleSort that takes an array of integers and sorts them.the following is the...

write a method bubbleSort that takes an array of integers and sorts them.the following is the pseudocode of bubble sort algorithm

swapped = true
while swapped
swapped = false
for j from O to N - 1
if number[j] > number [j + 1]
   swap ( numbers [j], numbers [j +1] )
       swapped = true

0 0
Add a comment Improve this question Transcribed image text
Answer #1
//C, C++ code
void bubbleSort(int arr[], int n)
{
    int i, j, temp;
    for (i = 0; i < n - 1; i++) {
        for (j = 0; j < n - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
}

Add a comment
Know the answer?
Add Answer to:
write a method bubbleSort that takes an array of integers and sorts them.the following is the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT