dikshantrajput / Hacktoberfest-accepted-2022

This repository is for everyone who wants to participate in Hacktoberfest 2022. Anyone can contribute/add quality code or projects for your Swags (T- Shirt), must be relevant that can add some value to this repository
114 stars 458 forks source link

Create bubbleSort.cpp #653

Open SONIYAPATIDAR opened 1 year ago

SONIYAPATIDAR commented 1 year ago

include

include

using namespace std; void bubbleSort(vector&arr){ for(int i=0;i<arr.size(); i++){ bool swaped=false; for(int j=0; j<arr.size()-1-i; j++){ if(arr[j]>arr[j+1]){ swaped=true;

    int t =arr[j+1];

    arr[j+1]=arr[j];
    arr[j]= t;
  }

}
if(swaped==false){
  break;
}

} for(int ele:arr){ cout<<ele<<" ";

 }
 cout<<"\n";

}

int main(){ vectorarr={1,4,6,8,5,9}; bubbleSort(arr);