Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
911 views
in Arrays by (29.8k points)
closed by

1. Write C++ program for sorting a list of numbers using Bubble Sort Method.

2. Write the different passes of sorting the following numbers using Bubble Sort. 32, 21, 9, 17, 5

1 Answer

+1 vote
by (29.6k points)
selected by
 
Best answer

1. Example for Bubble sort is given below

2. Bubble sort (ascending order): 

Consider the first 2 elements of the numbers and compare it. 32 is greater than 21 then interchange both of them. Then the numbers are 

21, 32, 9, 17, 5 

Next compare 32 and 9. Here 32 is greater so interchange both of them. Then the numbers are 

21, 9, 32, 17, 5 

Next compare 32 and 7. Then interchange and the numbers are 

21, 9, 17, 32, 5 

Next compare 32 and 5. Then interchange and the numbers are 

21, 9, 17, 5, 32. 

After the first phase the largest number is on the right side. Similarly do the remaining. At last we will get the result as follows. 

5, 9, 17, 21, 32

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...