SabirSazzad

Bubble Sort

Feb 26th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int Size,i,j,temp,a=0;
  7.     cout << "Input Array Size: ";
  8.     cin >> Size;
  9.     int Num[Size];
  10.     cout << "Input Values....\n";
  11.     for(i=0; i<Size; i++)
  12.     {
  13.         cin >> Num[i];
  14.     }
  15.     for(i=0; i<Size; i++)
  16.     {
  17.         for(j=a; j<Size-1; j++)
  18.         {
  19.             if(Num[j] > Num[j+1])
  20.             {
  21.                 temp = Num[j];
  22.                 Num[j] = Num[j+1];
  23.                 Num[j+1] = temp;
  24.                 a++;
  25.             }
  26.         }
  27.     }
  28.     cout << "\nAfter Sorting..." <<endl;
  29.     for(i=0; i<Size; i++)
  30.     {
  31.         cout << Num[i] << " ";
  32.     }
  33.     cout << "\n";
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment