Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

bubblesort c++

#include<iostream>
using namespace std;
int main ()
{
   int i, j,temp,pass=0;
   int a[10] = {10,2,0,14,43,25,18,1,5,45};
   cout <<"Input list ...
";
   for(i = 0; i<10; i++) {
      cout <<a[i]<<"	";
   }
cout<<endl;
for(i = 0; i<10; i++) {
   for(j = i+1; j<10; j++)
   {
      if(a[j] < a[i]) {
         temp = a[i];
         a[i] = a[j];
         a[j] = temp;
      }
   }
pass++;
}
cout <<"Sorted Element List ...
";
for(i = 0; i<10; i++) {
   cout <<a[i]<<"	";
}
cout<<"
Number of passes taken to sort the list:"<<pass<<endl;
return 0;
}
Source by www.softwaretestinghelp.com #
 
PREVIOUS NEXT
Tagged: #bubblesort
ADD COMMENT
Topic
Name
5+9 =