The number of swappings needed to short the numbers 8, 22, 7, 9, 31, 19, 5, 13 in ascending order using bubble sort is 1. 11 2. 12 3. 13 4. 14

Questions by Rujul   answers by Rujul

Showing Answers 1 - 18 of 18 Answers

Ashish Parik

  • Mar 12th, 2007
 

14 swapings r req. in case of bubble sort

  Was this answer useful?  Yes

Ranjan Kumar Ojha

  • Mar 13th, 2007
 

ans will be 14. you can check.

#include<iostream>
using namespace std;
int main()
{
    int a[]={ 8, 22, 7, 9, 31, 19, 5, 13 };int counter=0;
    for(int i=0;i<8;i++)
    {
        for(int j=0;j<8-i-1;j++)
        {
            if(a[j]>a[j+1])
            {
                int t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
                counter++;
            }
        }
    }
    //for(int i=0;i<8;i++)
    //cout<<a[i]<<" ";
    cout<<"n"<<counter;
    system("pause");
    return 0;
}

  Was this answer useful?  Yes

Nitish Kamal

  • Jan 27th, 2013
 

14 is answer

  Was this answer useful?  Yes

majed

  • Aug 31st, 2015
 

16=(8*8)/4

  Was this answer useful?  Yes

Diksha

  • Oct 12th, 2015
 

14 is the answer

  Was this answer useful?  Yes

Jenny

  • May 9th, 2017
 

14

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions