8/7/2019 Algorithims Labmanual 3 Solve
1/3
Q.1 Convert the Bubble Sort algorithm into C++ Code.
1. #include
2. #include
3. const int size=8;
4. main()5. {
6. clrscr();7. int Array[size];
8. int i,j,temp;
9. cout
8/7/2019 Algorithims Labmanual 3 Solve
2/3
Q.4 Run the above code for the following array: A={32, 54, 27, 80, 63, 23, 11,
57}Also print the result for each pass of the algorithm.
#include
#include
main()
{
clrscr();int Array[8]={32,54,27,80,63,23,11,57};
int i,j,temp,k;
for(i=0 ; i
8/7/2019 Algorithims Labmanual 3 Solve
3/3
Output:Pass 1:
32, 54,27,80,63,23,11,5732,27,54,80,63,23,11,57
32,27,54,80,63,23,11,57
32, 27,54,63,80,23,11,5732, 27,54,63,23,80,11,57
32, 27,54,63,23,11,80,57
32, 27,54,63,23,11,57,80Pass 2:
27, 32,54,63,23,11,57,80
27, 32,54,63,23,11,57,80
27, 32,54,63,23,11,57,8027, 32,54,23,63,11,57,80
27, 32,54,23,11,63,57,80
27, 32,54,23,11,57,63,80,
27, 32,54,23,11,57,63,80Pass 3:
27, 32,54,23,11,57,63,80
27, 32,54,23,11,57,63,80
27, 32,23,54,11,57,63,8027,32, 23,11,54,57,63,80
27, 32,23,11,54,57,63,80
27, 32,23,11,54,57,63,80
27, 32,23,11,54,57,63,80Pass 4:
27, 32,23,11,54,57,63,8027, 23,32,11,54,57,63,8027, 23,11,32,54,57,63,80
27, 23,11,32,54,57,63,80
27, 23,11,32,54,57,63,8027, 23,11,32,54,57,63,80
Pass 5:
23, 27,11,32,54,57,63,8023, 11,27,32,54,57,63,80
23, 11,27,32,54,57,63,80
23, 11,27,32,54,57,63,8023, 11,27,32,54,57,63,80
23, 11,27,32,54,57,63,80Pass6:
11, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,8011, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,80
Pass7:11, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,8011, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,8011, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,80Pass8:
11, 23,27,32,54,57,63,8011, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,8011, 23,27,32,54,57,63,8011, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,80
11, 23,27,32,54,57,63,80
Recommended