Bubble Sort

PHOTO EMBED

Wed Jun 02 2021 10:37:42 GMT+0000 (Coordinated Universal Time)

Saved by @ksp_2000 #c++

class Solution
{
    public:
    //Function to sort the array using bubble sort algorithm.
    void bubbleSort(int arr[], int n)
    {
      int flag=0;
    for(int k=1;k<=n-1;k++){
        for(int j=0;j<=n-k-1;j++){
            if(arr[j]>arr[j+1]){
                swap(&arr[j],&arr[j+1]);
              flag=1;
            }
        }
      if(flag==0)
        break;
    }
    }
    void swap(int *xp,int *yp){
        int temp=*xp;
        *xp=*yp;
        *yp=temp;
    }
};
content_copyCOPY