daily pastebin goal
59%
SHARE
TWEET

BubbleSort()

delvinkrasniqi Jan 24th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //BubbleSort
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. //Sortimi
  7. void Sort(int A[] , int size)
  8. {
  9.     bool swapped=true;
  10.     int j=0 , tmp;
  11.    
  12.     while (swapped)
  13.     {
  14.         swapped=false;
  15.         j++;
  16.         for (int i=0; i<size-j;i++)
  17.         {
  18.             if (A[i]>A[i+1])
  19.             {
  20.                 tmp =A[i];
  21.                 A[i]=A[i+1];
  22.                 A[i+1]=tmp;
  23.                
  24.                 swapped=true;
  25.             }
  26.         }
  27.     }
  28. }
  29. //Printimi
  30. void Print(int A[],int size)
  31. {
  32.     for (int i=0;i<size;i++)
  33.     {
  34.         cout <<A[i]<<endl;
  35.     }
  36. }
  37.  
  38. int main()
  39. {
  40.     int A[]={1,25,23,0,155,99};
  41.    
  42.     int size=sizeof(A)/sizeof(int);
  43.     Sort(A,size);
  44.     cout <<"Vargu i sortuar : ";
  45.     Print (A,size);
  46.    
  47.     return 0;
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top